I had read that I can mark folders with \"do not backup\" attribute with ios 5.1 and later
As i understand, in such case all contents of directory will be excluded f
First, post this on the internal Apple forums and see if you can get an Apple engineer to respond, which I doubt. Problem is even if it works today it may break later.
Suggestions:
1) create a folder in Documents, mark it, then only store files in it.
2) add a method to your app delegate that takes a file name parameter, then when called locates the file and marks it. In this case you need to insure you call it after every file creation action.
Yes you can set the do not backup
flag for the folders(file) of Document directory.
do not backup
attribute works on marked files regardless of what directory they are in, including the Documents directory.These files will not be purged and will not be included in the user's iCloud
backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.
for more information for the same go through this link
Below methods set the Do not back up flag to avoiding the unwanted backup|deletion from the app directory (Document and Cache).just need to call below method and pass url for the Folder(File).
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
if (&NSURLIsExcludedFromBackupKey == nil) { // for iOS <= 5.0.1
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
} else { // For iOS >= 5.1
NSError *error = nil;
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return error == nil;
}
}
func addSkipBackupAttributeToItemAtURL(filePath:String) -> Bool
{
let URL:NSURL = NSURL.fileURLWithPath(filePath)
assert(NSFileManager.defaultManager().fileExistsAtPath(filePath), "File \(filePath) does not exist")
var success: Bool
do {
try URL.setResourceValue(true, forKey:NSURLIsExcludedFromBackupKey)
success = true
} catch let error as NSError {
success = false
print("Error excluding \(URL.lastPathComponent) from backup \(error)");
}
return success
}
From the Apple docs, for iOS 5.1 or later, you should use this:
- (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;
}