未在iOS 9 OSStatus -34018上加载KeychainItemWrapper(errSecMissingEntitlement) [英] KeychainItemWrapper not getting loaded on iOS 9 OSStatus -34018 (errSecMissingEntitlement)
问题描述
我一直在使用KeychainItemWrapper很好.但是由于我已经将手机更新为iOS 9,因此出于某种原因它不存储sessionID.
I've been using KeychainItemWrapper just fine. But since I've updated my phone to iOS 9, it doesn't store the sessionID for some reason.
+ (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...**
}
}
有人知道发生了什么吗?
Anybody know whats going on?
编辑
最奇怪的事情:它不时发生,并且始终处于调试模式.
Weirdest thing: it only happens from time to time and always in debug mode.
EDIT2
由于这仅在调试模式下发生,因此我通常会根据变量的类型执行两种解决方法: -始终保持本地从钥匙串加载的最后一个有效变量(例如sessionID),并在调试模式下将其用作备份 -在调试时尽可能忽略无效值(在这种情况下,我将添加一个附加的控制变量以允许/禁止这些无效值)
As this only occurs in debug mode, there are two work arounds that I usually do depending on the type of variable: - Always keep the last valid variable loaded from the keychain locally (for instance a sessionID) and use it as a backup when in debug mode - Ignore invalid value(s) if possible when in debug (in this case I would add an additional control variable to allow/disallow these invalid value(s))
(使用#ifdef DEBUG检查您是否处于调试模式)
(use #ifdef DEBUG to check if you're in debug mode)
推荐答案
根据Apple的说法,目前没有解决方案. https://forums.developer.apple.com/thread/4743
According to Apple there is no solution right now. https://forums.developer.apple.com/thread/4743
这篇关于未在iOS 9 OSStatus -34018上加载KeychainItemWrapper(errSecMissingEntitlement)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!