我试图阻止 iTunes 备份整个文件夹。我关注了技术报告http://developer.apple.com/library/ios/#qa/qa1719/_index.html http://developer.apple.com/library/ios/#qa/qa1719/_index.html但似乎 flag 总是为零。我使用 IOS 5.1 在模拟器和设备上尝试过。但没有任何帮助。这些方法每次都返回“成功”,但 flag 仍然为零。
+ (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;
}
我刚刚在我的应用程序中修复了这个问题,虽然有点令人沮丧,但最终一切都进展顺利。
所以,这是代码addSkipBackupAttributeToItemAtURL https://gist.github.com/1999985。您可能想检查一下。它也处理 5.0.1 和 5.0。您只在代码中处理 5.1 及更高版本。
BUT:
假设您有一个 NSString *path - 文件 /folder 的路径,不要调用该方法:
[NSURL urlWithString:path];
它适用于 5.0.1,但不适用于 5.1 及更高版本。
Instead use [NSURL fileURLWithPath:path];
So: [MyClass addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:path]];
事实上,我认为这是您的代码的唯一问题。采用我链接到的方法,只会提供向后兼容性,这是一个很好的补充。
希望这可以帮助。
问候,
乔治
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)