[英]KeychainItemWrapper not getting loaded on iOS 9 OSStatus -34018 (errSecMissingEntitlement)
I've been using KeychainItemWrapper just fine. 我一直在使用KeychainItemWrapper很好。 But since I've updated my phone to iOS 9, it doesn't store the sessionID for some reason.
但是由于我已经将手机更新为iOS 9,因此出于某种原因它不存储sessionID。
+ (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? 有人知道发生了什么吗?
EDIT 编辑
Weirdest thing: it only happens from time to time and always in debug mode. 最奇怪的事情:它不时发生,并且始终处于调试模式。
EDIT2 EDIT2
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)) 由于这仅在调试模式下发生,因此我通常会根据变量类型进行两种解决方法:-始终将本地从钥匙串加载的最后一个有效变量(例如sessionID)始终保存在本地,并在以下情况下用作备份调试模式-在调试时尽可能忽略无效值(在这种情况下,我将添加一个附加的控制变量以允许/禁止这些无效值)
(use #ifdef DEBUG to check if you're in debug mode) (使用#ifdef DEBUG检查您是否处于调试模式)
According to Apple there is no solution right now. 据苹果称,目前没有解决方案。 https://forums.developer.apple.com/thread/4743
https://forums.developer.apple.com/thread/4743
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.