我无法让这个工作。我的应用程序因允许备份不必要的文件而被拒绝。为了阻止这种情况,我被告知要使用addSkipBackupAttributeToItemAtURL来标记不要备份的文件。
我在AppDelegate中放置了以下由Apple提供的代码。
- (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);
} else {
NSLog(@"\n\nFile %@ removed from backup.\n\n", URL);
}
return success;
}
然后我在didFinishLaunchingWithOptions
中添加以下内容[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"blue" ofType:@"jpg"]]];
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"fred" ofType:@"jpg"]]];
它在模拟器中工作正常。在实际的手机上,它不起作用,并给我我认为解决了权限错误。
Error excluding blue.jpg from backup Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1740741c0 {NSURL=file:///private/var/mobile/Containers/Bundle/Application/C8559ABA-181E-4686-A5ED-2ADCA283D2E4/PetJournal.app/blue.jpg, NSFilePath=/private/var/mobile/Containers/Bundle/Application/C8559ABA-181E-4686-A5ED-2ADCA283D2E4/PetJournal.app/blue.jpg, NSUnderlyingError=0x174058e10 "The operation couldn’t be completed. Operation not permitted"}
任何人都可以帮助指导我完成这项工作。