提前感谢您的帮助。 我已经排除了iCloud备份的文件夹,但它仍在备份文件,当我访问iCould时,它已备份。我使用以下代码来排除目录备份。
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
// 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;
}
我将上述方法称为下面的
NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDir = [Paths objectAtIndex:0];
NSString *downloadFolder = [libraryDir stringByAppendingPathComponent:@"downloads"];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:downloadFolder])
[[NSFileManager defaultManager] createDirectoryAtPath:downloadFolder withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
NSURL *documentURL = [NSURL URLWithString:downloadFolder];
[self addSkipBackupAttributeToItemAtURL:documentURL];
答案 0 :(得分:0)
导入此sys / xattr.h
- (BOOL) addSkipBackupAttributeToItemAtPath: (NSString *) path {
BOOL success = NO;
const char* filePath = [path fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
void* check = (void *)&NSURLIsExcludedFromBackupKey;
if (check != NULL) {
// First try and remove the extended attribute if it is present
int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
if (result != -1) {
// The attribute exists, we need to remove it
int removeResult = removexattr(filePath, attrName, 0);
if (removeResult == 0) {
NSLog(@"Removed extended attribute on item at path %@", path);
}
}
NSURL *url = [NSURL fileURLWithPath: path];
success = [url setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: nil];
} else {
// iOS 5.0.1 and lower
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
success = (result == 0);
}
NSLog(@"Add skip backup attribute for item at path: %@, result: %d", path, success);
return success;
}
我希望这会奏效......