Skip to content

Instantly share code, notes, and snippets.

@pita5
Created September 20, 2013 10:47
Show Gist options
  • Save pita5/6635840 to your computer and use it in GitHub Desktop.
Save pita5/6635840 to your computer and use it in GitHub Desktop.
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
if (&NSURLIsExcludedFromBackupKey == nil) { // 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 { // iOS >= 5.1
NSError *error = nil;
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return error == nil;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment