我似乎无法从我的代码中获取备份属性参数。不管我看起来如何做,该方法返回false与“未知的错误-1”。我曾尝试跳过备份方法的不同迭代,但下面是我使用的是最新的基础上,另一篇文章,我发现:Obj-C - 添加'skip-backup'属性总是失败
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
if (&NSURLIsExcludedFromBackupKey == nil) {
// iOS 5.0.1 and lower
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
} else {
// 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 file %@", URL);
}
}
// Set the new key
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}
我的方法调用如下所示(它总是打印“不成功“):
if ([self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:filePath]]) {
NSLog(@"success!");
} else {
NSLog(@"not successful");
}
而filePath是文档文件夹映像的NSString路径。我记录一个图像路径的示例如下:
/var/mobile/Applications/B3583D06-38BC-45F0-A027-E79997F0EC60/Documents/myImage.png
在我的应用程序,它通过循环的所有(众多)文件,我推送到那里,并且它添加了这个属性。它在每一个都失败了。由于这些动态驱动文件对离线功能的要求很高,我需要能够实现这一目标。我没有看到很多其他人都有这个问题,所以这告诉我我可能会错过这里明显的东西,哈哈。
我发现这个职位:Why was my application still rejected after excluding files from iCloud backup using this code?
这看起来很有希望,什么我的问题可能是,但目前还没有真正关心如何具体解决任何细节(它只是建议使用/库,而不是文档的夹?)。
感谢任何人提前谁可以帮助! -Vincent
什么是您的iOS SDK版本和iOS目标版本? – 2012-07-19 16:33:14
对不起,我应该提到这一点。 iOS SDK是:5.1,iOS目标版本是:4.3(但如果需要,可以提出这个问题)。不过,我的设备是最新的操作系统,这就是我从Xcode运行应用程序的地方。谢谢! – svguerin3 2012-07-19 16:37:50