开发者

Exclude files from application backup

开发者 https://www.devze.com 2023-01-08 15:31 出处:网络
Is there a way to exclude some of the files in your application bundle from being backed up to the user\'s computer开发者_运维知识库?I have a photo browsing application that allows you to store photos

Is there a way to exclude some of the files in your application bundle from being backed up to the user's computer开发者_运维知识库? I have a photo browsing application that allows you to store photos/videos locally, when a user goes sync their device and the application is backed up its taking a really long time since its backing up all the locally stored photos/videos as well. Is there perhaps a directory (/tmp/?) that won't be backed up?


Yes you must put files that you don't want to backup to Caches directory. Path can be obtained:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *cachesPath = [paths objectAtIndex:0]; 


iOS Applocation Programming Guide: A Few Important Application Directories talks about which folders are backed up and which aren't. You should use <Application_Home>/Library/Caches to store persistent data that does not need to be backed up.

iPhone Application Programming Guide: Getting Paths to Application Directories shows how to get the path to that folder by using NSSearchPathForDirectoriesInDomains with NSCachesDirectory parameter.


/Library/Caches is not guaranteed to be kept during application updates. This could be a problem for your media files.


The Apple docs suggest this in iOS 5.1 and later:

NSURL *storeUrl = [NSURL fileURLWithPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"your_file"]];

NSError *error;
[storeUrl setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];

if (error) {
    NSLog(@"couldn't exclude database from backups: %@", [error localizedDescription]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消