Exclude files from application backup

Is there a way to exclude some files from your application package from a backup to a user's computer? I have an application for viewing photos that allows you to locally store photos / videos when the user synchronizes their device, and the application is backed up for a very long time from the moment all the locally saved photos and videos are created. Could there be a directory (/ tmp /?) That will not be copied?

+4
source share
4 answers

Yes, you must put the files you do not want to back up to the Caches directory. The path can be obtained:

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

IOS Application Programming Guide: Some important application directories tell you which folders were copied and which weren’t. You must use <Application_Home>/Library/Caches to store persistent data that does not need to be backed up.

IPhone Application Programming Guide: NSSearchPathForDirectoriesInDomains shows how to get the path to this folder using NSSearchPathForDirectoriesInDomains with the NSCachesDirectory parameter.

+4
source

/ Library / Caches are not guaranteed during application updates. This may be a problem for your media files.

+3
source

Apple docs offer 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
source

Source: https://habr.com/ru/post/1316321/


All Articles