I have a few unit tests to verify that the way I work with Keychain is correct and data are in same form when I load them.
Tests were running ok until update to XCode 9. At the moment, KeychainService return -50 (not saved).
According to this question, it was solved by adding Host to unit tests. However, my tests are in framework project and there is no app to use as a host.
let query = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrAccount as String : key,
kSecValueData as String : data ] as [String : Any]
SecItemDelete(query as CFDictionary)
SecItemAdd(query as CFDictionary, nil)
What is recommended solution? I expect just some configuration in XCode, moving tests into app is not a proper solution for me.
With Xcode 9 test bundles require a host app to access the keychain from within the iOS simulator, see https://stackoverflow.com/a/46317131/5082444.
Simply add an app target and set it as the host application for your unit test bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With