How to remove tmp directory files of an ios app?

前端 未结 6 998
囚心锁ツ
囚心锁ツ 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:35

    Try this code to remove NSTemporaryDirectory files

    -(void)deleteTempData
    {
        NSString *tmpDirectory = NSTemporaryDirectory();
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSArray *cacheFiles = [fileManager contentsOfDirectoryAtPath:tmpDirectory error:&error];
        for (NSString *file in cacheFiles)
        {
            error = nil;
            [fileManager removeItemAtPath:[tmpDirectory stringByAppendingPathComponent:file] error:&error];
        }
    }
    

    and to check data remove or not write code in didFinishLaunchingWithOptions

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [self.window makeKeyAndVisible];
    
        NSString *tmpDirectory = NSTemporaryDirectory();
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSArray *cacheFiles = [fileManager contentsOfDirectoryAtPath:tmpDirectory error:&error];
        NSLog(@"TempFile Count ::%lu",(unsigned long)cacheFiles.count);
    
        return YES;
    }
    

提交回复
热议问题