KeychainItemWrapper not loading on iOS 9 OSStatus -34018 (errSecMissingEntitlement)

I use KeychainItemWrapper just fine. But since I upgraded my phone to iOS 9, for some reason it does not store the session identifier.

    + (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 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...**
    }
}

Does anyone know what is going on?

EDIT

The strangest thing: this happens only from time to time and always in debug mode.

EDIT2

, , :  - , , (, sessionID)  - (-), ( , / )

( #ifdef DEBUG, , )

+2

Source: https://habr.com/ru/post/1542615/


All Articles