我的应用被拒绝,因为它必须遵循 iOS 数据存储指南。我已经在 stackoverflow 上阅读了一些答案,并且已经阅读了一些博客......我知道我的问题,在第一次启动应用程序时,我复制了 1 个 sqlite 数据库并将一些图像解压缩到文档文件夹中。问题是 icloud 会自动备份文档目录中的任何文件。我不需要在我的应用程序中使用 icloud,但我的文件必须保留在文档文件夹中,因为它们是我的应用程序的基础数据并且必须保留(缓存文件夹或临时文件夹不是正确的解决方案)。所以我读到了一个标志,我可以逐个文件设置以禁止备份:
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
我还了解到此方法仅适用于高于 5.0.1 的 ios,在其他版本中它将被简单地忽略(我已将我的 ios 部署目标设置为 4.3)...如果我使用此方法我的应用程序将再次被拒绝,因为旧的 ios 设备备份没有管理?如果是,是否有一种跨 iosversion 方法来设置 NSURLIsExcludedFromBackupKey?
编辑 对不起,icloud 不存在于 ios 5.0 之前的版本中,所以我认为问题仅与版本 5.0 和 5.0.1 之间的差异有关,我错了吗?
最佳答案
我已经通过这个方法传递了所有将存储在文档文件夹中的文件。
试试这个
-(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
NSError *error = nil;
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return error == nil;
}
}
我在 Stack Overflow 中找到了这个方法:
关于iOS 数据存储指南拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10206485/