sam*_*tte 13 iphone objective-c ios
检查可用性似乎工作正常,但我似乎无法设置NSURLIsExcludedFromBackupKey
密钥而不会在启动时出现此崩溃:
dyld:未找到符号:_NSURLIsExcludedFromBackupKey引用自:/ Users/sam/Library/Application Support/iPhone Simulator/5.0/Applications/B0872A19-3230-481C-B5CE-D4BDE264FBDF/Transit.app/Transit预期:/ Applications/Xcode. app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Foundation in/Users/sam/Library/Application Support/iPhone Simulator/5.0/Applications /B0872A19-3230-481C-B5CE-D4BDE264FBDF/Transit.app/Transit
这是我的方法:
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
if (&NSURLIsExcludedFromBackupKey == nil)
return NO;
NSError *error;
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return (error != nil);
}
Run Code Online (Sandbox Code Playgroud)
如果我注释掉这一行,崩溃就会消失:
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
Run Code Online (Sandbox Code Playgroud)
我必须弱化基金会吗?
编辑:不确定它是否有所作为,但这种方法被放在一个NSFileManager
类别中.
tim*_*tim 19
这是iOS <= 5.0.1和> = 5.1的代码,包括@Cocoanetics提到的迁移技术.
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是iPhone 5.0模拟器的一个错误.我尝试在5.0设备上运行代码,没有崩溃.报告此错误为rdar:// 11017158.
编辑:这已在Xcode 4.5 DP2中修复(不确定它是否在4.4中).