Clement Bisaillon
Clement Bisaillon

Reputation: 5177

Keychain doesn't work when installing app using TestFlight

When i build my app directly to my iPhone i can store items in the keyChain but if i archive it and send it to to ItunesConnect and someone download it using testFlight it doesn't store the item in the keyChain

Here is the log of when he tries to access the keychain:

Dec  4 23:10:40  <Error>:  securityd_xpc_dictionary_handler    appName[2687] add The operation couldn’t be completed. (OSStatus error -25299 - duplicate item O,genp,7937CF51,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.123944Z,F87F1109)
Dec  4 23:10:40  <Error>:  SecOSStatusWith error:[-25299] The operation couldn’t be completed. (OSStatus error -25299 - Remote error : The operation couldn‚Äôt be completed. (OSStatus error -25299 - duplicate item O,genp,7937CF51,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.123944Z,F87F1109))
Dec  4 23:10:40  <Error>:  securityd_xpc_dictionary_handler appName[2687] add The operation couldn’t be completed. (OSStatus error -25299 - duplicate item O,genp,801FEEB1,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.146946Z,5CD00596)
Dec  4 23:10:40  <Error>:  SecOSStatusWith error:[-25299] The operation couldn’t be completed. (OSStatus error -25299 - Remote error : The operation couldn‚Äôt be completed. (OSStatus error -25299 - duplicate item O,genp,801FEEB1,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.146946Z,5CD00596))
Dec  4 23:10:40  <Error>:  securityd_xpc_dictionary_handler appName[2687] add The operation couldn’t be completed. (OSStatus error -25299 - duplicate item O,genp,7937CF51,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.20269Z,846CAAC0)
Dec  4 23:10:40  <Error>:  SecOSStatusWith error:[-25299] The operation couldn’t be completed. (OSStatus error -25299 - Remote error : The operation couldn‚Äôt be completed. (OSStatus error -25299 - duplicate item O,genp,7937CF51,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.20269Z,846CAAC0))
Dec  4 23:10:40  <Error>:  securityd_xpc_dictionary_handler appName[2687] add The operation couldn’t be completed. (OSStatus error -25299 - duplicate item O,genp,801FEEB1,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.222921Z,7E11CA46)
Dec  4 23:10:40  <Error>:  SecOSStatusWith error:[-25299] The operation couldn’t be completed. (OSStatus error -25299 - Remote error : The operation couldn‚Äôt be completed. (OSStatus error -25299 - duplicate item O,genp,801FEEB1,L,ak,bundleID.appName,0,acct,svce,gena,v_Data,20141205041040.222921Z,7E11CA46))

EDIT

This is what i use to put something in the keychain: https://github.com/jrendel/KeychainWrapper/blob/master/KeychainWrapper/KeychainWrapper.swift

i don't know if it uses kSecClassGenericPassword. This is what i do to put the info in the keychain:

KeychainWrapper.setString(self.username.text, forKey: "username")
KeychainWrapper.setString(self.password.text, forKey: "password")

And i get it back using:

if let u = KeychainWrapper.stringForKey("username") {
        username = KeychainWrapper.stringForKey("username")!
        password = KeychainWrapper.stringForKey("password")!
}

Upvotes: 2

Views: 2267

Answers (2)

Gil
Gil

Reputation: 46

It seems to be a bug with the Swift compiler.

It should work if you change the "Optimization Level" for "Release" to "None" in your target's "Build Settings"

Check the answer by Mark in this thread: https://stackoverflow.com/a/26467942/2977842

Hope this helps!

Upvotes: 1

bjtitus
bjtitus

Reputation: 4270

You should check the console on the device you are unable to access the keychain on and look for logs indicating an issue with keychain access. This sounds like an issue with entitlements. Check out this FAQ on how to address the issue you will probably see in the console:

https://developer.apple.com/library/ios/qa/qa1726/_index.html

EDIT

I think you are probably not filling out all of the necessary information for the keychain item. If you are using kSecClassGenericPassword then you need to fill out both kSecAttrAccount and kSecAttrService

This blog post has more details: http://useyourloaf.com/blog/2010/04/28/keychain-duplicate-item-when-adding-password.html

This StackOverflow question lists the combination which form the primary keys: What makes a keychain item unique (in iOS)?

Here's another question, for good measure, with your same issue: Error saving in the keychain with iphone sdk

Upvotes: 1

Related Questions