IOS 审核 屏蔽Documents目录自动备份到iCloud
//在didFinishLaunchingWithOptions函数后调用addNotBackUpiCloud即可屏蔽documents下所有文件自动备份到iCloud.
- (void)addNotBackUpiCloud{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString* docPath = [documentPaths objectAtIndex:0];
[self addSkipBackupAttributeToItemAtURL:docPath];
}
/**
*屏蔽ios文件不备份到icloud
*/
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSString *)filePathString{
NSURL* URL = [NSURL fileURLWithPath:filePathString];
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;
}
网友评论