I\'m trying to prevent my app backing up files to iCloud but have become completely confused and a little lost.
-EDIT-
I\'ve updated this to reflect the chan
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}
NSURL *documentURLWithExtension = [documentURL URLByAppendingPathExtension:extensionType];
pass this "documentURLWithExtension
" to this function
[self addSkipBackupAttributeToItemAtURL:documentURLWithExtension];
In Swift:
//Path of document directory
var docPathAry : NSArray! = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
var docDirPathStr: AnyObject? = docPathAry.count > 0 ? docPathAry[0] : nil
self.addSkipBackupAttributeToItemAtURL(NSURL.fileURLWithPath(docDirPathStr as NSString))
and:
func addSkipBackupAttributeToItemAtURL(URL: NSURL!) -> Bool {
assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path))
var err : NSError? = nil
var success : Bool! = URL.setResourceValue(NSNumber.numberWithBool(true), forKey: NSURLIsExcludedFromBackupKey, error: &err)
if(!success) {
println("Error excluding \(URL.lastPathComponent) from backup\(err) ")
}
return success
}