Objective-C: Terminating app due to uncaught exception NSInternalInconsistencyException, reason: Couldn’t add the Keychain Item

Posted: June 22, 2015 in iOS, Objective C

I have updated my app to support Share Extension and it requires share keychain between containing App and extension, so that I need create a keychain access group. The app was working fine in simulator, but it will crash with the above exception in a real device. When debugging, I found the reason code is -25243.

The keychain wrapper i was using is from this link. https://gist.github.com/dhoerl/1170641

After troubleshooting for a few days, i found that the reason is that I was accessing using the wrong keychain access group.

-25243 is related to keychain permission and I didn’t see this error in simulator because simulator app wasn’t signed

For the sake of context, i set the keychain access group in Target->Keychain sharing, then directly accessed the keychain with the group name.  This is wrong because the actual keychain access group should be $(AppIdentifierPrefix)whatever.you.set. You can find it from entitlements.plist.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s