2

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?

EDIT

Weirdest thing: it only happens from time to time and always in debug mode.

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))

(use #ifdef DEBUG to check if you're in debug mode)

jonypz
  • 1,515
  • 1
  • 20
  • 35
  • 1
    Check this [SO Answer](http://stackoverflow.com/a/28256591/451475) Error: Error Domain=NSOSStatusErrorDomain Code=-34018 "The operation couldn’t be completed. – zaph Sep 03 '15 at 03:27
  • @zaph thanks! Whats the best work around? How did you solve this? – jonypz Sep 04 '15 at 00:16
  • I had the same issue o a contract earlier this year and never found an answer. Since you have current code that has this issue file a [bugreport](http://bugreport.apple.com) with Apple. – zaph Sep 04 '15 at 01:39
  • I had the same issue. – Toseef Khilji Jan 06 '16 at 12:31

1 Answers1

0

According to Apple there is no solution right now. https://forums.developer.apple.com/thread/4743

Noam Ma-Yafit
  • 256
  • 1
  • 3
  • 7