I am trying to prevent my application from archiving files in iCloud, but it is completely confused and a little lost.
-Edit -
I updated this to reflect the changes I made thanks to the posters below.
I want to prevent the backup of files that are uploaded to the applicationโs document directory.
So far, I have a class called PreventBackup with the following method:
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { NSError *error = nil; BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error]; if(!success){ NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); } NSLog(@"prevent backup method called without error"); return success; }
Then I call it with this code when the application starts:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory]; [PreventBackup addSkipBackupAttributeToItemAtURL:pathURL];
The fingerprints prevent backup method called without error , but the application still shows that they have the same amount of data to back up with it earlier.
Any idea where this is going wrong?
-EDIT 2 -
Ok, I think this is resolved. Files are uploaded to a subfolder called "downloads". changing the code above to read it like this seems to accomplish the trick:
NSString *downloadsFolder = [documentsDirectory stringByAppendingPathComponent:(@"/downloads")]; NSURL *pathURL= [NSURL fileURLWithPath:downloadsFolder]; [PreventBackup addSkipBackupAttributeToItemAtURL:pathURL];
Thank you all for your help.