我的 iPhone 应用程序包含大约 500 MB 数据。并且应用程序将离线使用该数据。所以我将该文件夹标记为不要在 iTunes 上备份/复制。所以我使用下面的网址: https://gist.github.com/1999985
但它说“NSURLIsExcludedFromBackupKey”未声明。我还尝试使用 https://developer.apple.com/library/ios/#qa/qa1719/_index.html 但我总是返回 false..
所以请让我知道它是如何工作的?
谢谢
最佳答案
NSURLIsExcludedFromBackupKey
应该可以在 5.1+ SDK 上正常编译。
由于该 key 不适用于 5.0,因此以下代码片段可以作为解决方法。
if (SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"5.0.1"))
{
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.1"))
{
NSError *error = nil;
//[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:@"NSURLIsExcludedFromBackupKey" error:&error];
return error == nil;
}
关于iphone - “NSURLIsExcludedFromBackupKey”未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10355931/