下面的代码,将避免让Documents被iCloud备份
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSURL *documentsUrl = [NSURL URLWithString:documentsDir];
[self skipBackupItemAtURL:documentsUrl];
...
}
- (BOOL)skipBackupItemAtURL:(NSURL *)URL
{
NSString *path = [URL path];
NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];
BOOL needsBackUp = [defauts boolForKey:path];
if(needsBackUp)
return YES;
assert([[NSFileManager defaultManager] fileExistsAtPath: path]);
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);
if(result == 0){
[defauts setBool:YES forKey:path];
[defauts synchronize];
return YES;
}
else {
return NO;
}
}