KeychainItemWrapper在iOS 9上未加载OSStatus -34018(errSecMissingEntitlement)

我一直在使用KeychainItemWrapper。 但是由于我已经将手机更新到iOS 9,因此出于某种原因它不存储会话ID。

+ (BOOL)createKeychainValue:(NSString *)value forIdentifier:(NSString *)identifier { NSMutableDictionary *dictionary = [self setupSearchDirectoryForIdentifier:identifier]; NSData *valueData = [value dataUsingEncoding:NSUTF8StringEncoding]; [dictionary setObject:valueData forKey:(__bridge id)kSecValueData]; // Protect the keychain entry so it's only valid when the device is unlocked at least once. [dictionary setObject:(__bridge id)kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible]; // **THIS LINE OF CODE RETURNS -34108** OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dictionary, NULL); // If the addition was successful, return. Otherwise, attempt to update existing key or quit (return NO). if (status == errSecSuccess) { return YES; } else if (status == errSecDuplicateItem){ return [self updateKeychainValue:value forIdentifier:identifier]; } else { return NO; **The call returns here...** } } 

有人知道发生了什么事?

编辑

最奇怪的是:它只是不时发生,始终处于debugging模式。

EDIT2

由于这只发生在debugging模式下,所以我通常会根据variables的types进行两个解决方法: – 始终保持从本地encryption钥匙串的最后一个有效variables(例如sessionID),并将其用作备份debugging模式 – 在debugging时忽略无效值(在这种情况下,我会添加一个额外的控制variables来允许/禁止这些无效的值)

(使用#ifdef DEBUG来检查你是否处于debugging模式)

据苹果说,目前没有解决办法。 https://forums.developer.apple.com/thread/4743