29,028
社区成员
发帖
与我相关
我的任务
分享
//设置禁止Document和Library目录下的文件同步到iCloud
-(void)addNotBackUpiCloud{
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *libPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
NSString *libPath = [libPaths objectAtIndex:0];
[self fileList:docPath];
[self fileList:libPath];
}
- (void)fileList:(NSString*)directory{
NSError *error = nil;
NSFileManager * fileManager = [NSFileManager defaultManager];
NSArray *fileList = [fileManager contentsOfDirectoryAtPath:directory error:&error];
for (NSString* each in fileList) {
NSMutableString* path = [[NSMutableString alloc]initWithString:directory];
[path appendFormat:@"/%@",each];
NSURL *filePath = [NSURL fileURLWithPath:path];
[self addSkipBackupAttributeToItemAtURL:filePath];
[self fileList:path];
}
}
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
//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;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self addNotBackUpiCloud];