2

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")!
}
Clément Bisaillon
  • 5,037
  • 8
  • 32
  • 53
  • what are you trying to store in the keychain? keychain items are per device or per user (iCloud), so if you put something into your own keychain via your app, it's not going to transfer magically to somebody else's keychain. – Michael Dautermann Nov 17 '14 at 20:16
  • I know i am trying to store the username and password that the user enter in a textfield – Clément Bisaillon Nov 17 '14 at 20:43

2 Answers2

1

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

Community
  • 1
  • 1
bjtitus
  • 4,231
  • 1
  • 27
  • 35
  • I don't think it's a problem with his device cause if i build it directly to it it works – Clément Bisaillon Nov 17 '14 at 20:42
  • I said nothing about the device and neither does the link. This is about the provisioning profile and entitlements that are included with the application. You may be using a different provisioning profile to build to your device for development than you are when you build for adhoc testing via TestFlight. Check the console like I suggested and see if you see the error mentioned in the link, if not, post back here with the message you see. – bjtitus Nov 17 '14 at 20:45
  • How do i see the console and log? I don't have his device with me – Clément Bisaillon Nov 17 '14 at 21:25
  • Have him follow these instructions while opening the app: http://support.omnigroup.com/ios-console-log – bjtitus Nov 17 '14 at 22:35
  • I have added the log of his device when he tries to access the keychain – Clément Bisaillon Dec 05 '14 at 04:22
  • @ClémentBisaillon just updated with an answer based on your console log – bjtitus Dec 05 '14 at 15:12
  • i have added things to my question – Clément Bisaillon Dec 05 '14 at 16:04
1

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!

Community
  • 1
  • 1
Gil
  • 46
  • 4