gpt4 book ai didi

iphone - 在 iOS 5.0 上使用 NSURLIsExcludedFromBackupKey 而不会崩溃

转载 作者:技术小花猫 更新时间:2023-10-29 10:20:10 32 4
gpt4 key购买 nike

可用性检查似乎工作正常,但我似乎无法设置 NSURLIsExcludedFromBackupKey 键而不会在启动时发生崩溃:

dyld: Symbol not found: _NSURLIsExcludedFromBackupKey Referenced from: /Users/sam/Library/Application Support/iPhone Simulator/5.0/Applications/B0872A19-3230-481C-B5CE-D4BDE264FBDF/Transit.app/Transit Expected in: /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);
}

如果我注释掉这一行,崩溃就会消失:

[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];

我必须弱链接 Foundation 吗?

编辑:不确定它是否有所作为,但这个方法放在 NSFileManager 类别中。

最佳答案

这是适用于 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];
}
}

关于iphone - 在 iOS 5.0 上使用 NSURLIsExcludedFromBackupKey 而不会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9620651/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com