- (BOOL)setResourceValue:(nullable id)value forKey:(NSURLResourceKey)key error:(NSError **)error
在开发中,如果APP需要存放比较大的文件的时候,同时又不希望被系统清理掉,那我么我们就需要把我们的资源保存在Documents目录下,但是我们又不希望他会被iCloud备份,因此就有了这个方法:
+ (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
NSURL* URL= [NSURL fileURLWithPath:filePathString];
NSError *error = nil;
//SURLIsExcludedFromBackupKey: 不被备份;
BOOL success = [URL setResourceValue:[NSNumber numberWithBool: YES] forKey:NSURLIsExcludedFromBackupKey error: &error];
if(!success) {
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}