我添加了链接2中描述的代码:我在图片下载并保存在目录后调用此方法。
-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
if (&NSURLIsExcludedFromBackupKey == NULL) {
// Use iOS 5.0.1 mechanism
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);
return result == 0;
}
else {
// Use NSURLIsExcludedFromBackupKey mechanism, iOS 5.1+
NSError *error = nil;
BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&error];
if(!success) {
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
else {
NSLog(@"Path is %@:", [URL path]);
}
//Check your error and take appropriate action
return success;
}
}
在 iCloud 中签入时,应用程序的大小仍然是 50.7 Mb(我正在使用 5.1.1 iOS 版本的 iPhone 上进行测试),因此使用 of flag 没有任何效果,尽管成功有一个“YES”值。请告诉我我做错了什么?