Will /Library/Caches be clear on app update?

前端 未结 5 1094
悲哀的现实
悲哀的现实 2021-01-30 11:19

In my iPhone app I\'m caching the raw data of some compressed files to save loading time. But those files may change in an update.

Will iOS clear /Library/Caches for me

5条回答
  •  旧时难觅i
    2021-01-30 12:13

    The caches directory will be purged if iOS is running out of space. If the user chooses "update all" from the app store options, it is likely that they will run out of space.

    You should only store files in the Caches directory if they can be recreated by your app. From what I understand, the media player in iOS7 will only play videos stored in caches directory, and here's how I clear them manually (just in case):

    -(void)deleteAllVideos
    {
        NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    
        NSFileManager* fileManager = [NSFileManager defaultManager];
        NSArray *directoryContent = [fileManager contentsOfDirectoryAtPath:cachePath error:NULL];
    
        NSError* error;
        NSString* fullFilePath = nil;
    
        for(NSString* fileName in directoryContent)
        {
            if([fileName hasSuffix:@".mp4"])
            {
    
                fullFilePath = [cachePath stringByAppendingPathComponent:fileName];
                [fileManager removeItemAtPath:fullFilePath error:&error];
    
                if(error)
                {
                    DLog(@"Error: %@",error);
                }
            }
        }
    
    }
    

提交回复
热议问题