我试图防止整个文件夹被iTunes备份。我遵循了技术报告http://developer.apple.com/library/ios/#qa/qa1719/_index.html但似乎 falg 每次都是零。我使用在模拟器和设备上试用过的 IOS 5.1。但没有任何帮助。这些方法每次都返回“成功”,但标志仍然为零。
+ (BOOL) hasSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
NSError *error = nil;
id flag = nil;
BOOL success = [URL getResourceValue: &flag
forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
return false;
}
if (!flag)
return false;
return [flag boolValue];
}
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
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)removeSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: NO]
forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}