SecItemAdd returns -50 on Xcode 9

The following code:

    var newItem = [String: Any]()

    newItem[kSecClass as String] = aValue
    newItem[kSecAttrService as String] = aValue
    newItem[kSecAttrAccount as String] = aValue
    newItem[kSecValueData as String] = aValue
    newItem[kSecAttrAccessible as String] = aValue

    // Add a the new item to the keychain.
    let status = SecItemAdd(newItem as CFDictionary, nil)

    if status != noErr {
        print("Error during access token save. \(status)")
    }

Works perfectly on Xcode 8 without returning any error, and returns -50 error (aka. errSecParam) on Xcode 9.

Any help?

1 answer

  • answered 2017-10-11 10:03 Tulleb

    I found my answer. I needed to add an host application for the Keychain framework to get a full context.

    In my xxxxxTests target, I had to setup my main app in the Host Application menu (in the General tab).

    Weird thing is that it wasn't necessary on Xcode 8.