How to remove tmp directory files of an ios app?

前端 未结 6 991
囚心锁ツ
囚心锁ツ 2020-12-05 02:18

I\'m working on an app that uses the iPhone camera and after making several tests I\'ve realised that it is storing all the captured videos on the tmp directory of the app.

6条回答
  •  遥遥无期
    2020-12-05 02:29

    This works on a jailbroken iPad, but I think this should work on a non-jailbroken device also.

    -(void) clearCache
    {
        for(int i=0; i< 100;i++)
        {
            NSLog(@"warning CLEAR CACHE--------");
        }
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError * error;
        NSArray * cacheFiles = [fileManager contentsOfDirectoryAtPath:NSTemporaryDirectory() error:&error];
    
        for(NSString * file in cacheFiles)
        {
            error=nil;
            NSString * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:file ];
            NSLog(@"filePath to remove = %@",filePath);
    
            BOOL removed =[fileManager removeItemAtPath:filePath error:&error];
            if(removed ==NO)
            {
                NSLog(@"removed ==NO");
            }
            if(error)
            {
                NSLog(@"%@", [error description]);
            }
        }
    }
    

提交回复
热议问题