0

In my iOS app, I am using KeychainItemWrapper given by Apple to save some important data of my app.

App works fine when I deploy app on mobile using developer provisioning profile, but when same app I deploy by creating distribution build using "Distribution" profile app crashes.

I analyzed device log but not able to figure out the issue. It crashes "writeToKeyChain" method. I am not able to find out why this is happening only for distribution profile build.

Any Idea why this is happening? Any one faced this issue before?

iOS : 9.3.1
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY


  CoreFoundation                    0x1817fee38 __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x180e63f80 objc_exception_throw + 56
2   CoreFoundation                  0x1817fed08 +[NSException raise:format:arguments:] + 108
3   Foundation                      0x182184124 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4   MyApp                           0x10017fe6c -[KeychainItemWrapper writeToKeychain] (KeychainItemWrapper.m:328)
5   MyApp                           0x10017f1c4 -[KeychainItemWrapper setObject:forKey:] (KeychainItemWrapper.m:177)
6   MyApp                           0x1000c61cc +[MyKeyChainWrappper fetchInfo:] (MyKeyChainWrappper.m:41)

EDIT:

KeychainItemWrapper Initialisation code

 KeychainItemWrapper* mykeyChain = [[KeychainItemWrapper alloc]    initWithIdentifier:@"My_Identifier" accessGroup:[[NSBundle mainBundle]    bundleIdentifier]];


  [mykeyChain setObject:(__bridge id)(kSecAttrAccessibleWhenUnlocked) forKey:(__bridge id)(kSecAttrAccessible)];
Swapnil
  • 1,858
  • 2
  • 22
  • 49
  • Since an exception was raised, there should be a message with the details of the exception, but it looks like the write to the keychain has failed. Does the device have a passcode set? The crash is a result of the NSAssert failing on line 328. Perhaps remove the assertion and log the error somewhere? – Paulw11 May 12 '16 at 20:35
  • Assertion is for item adding in keychain, if I comment it, it doesn't crash but also expected value doesn't get which cause app to crash – Swapnil May 12 '16 at 21:07
  • I am wondering why issue is profile specific since it work with developer profile – Swapnil May 12 '16 at 21:08
  • Removing the assertion will remove the crash, but not the underlying problem that is causing the crash. You need to get the details of the error that was returned from the keychain and log this so you can diagnose the problem – Paulw11 May 12 '16 at 21:10
  • How I can log failure of SecItemAdd function? There is no any error block or object return by it? It gives only status "OSStatus" – Swapnil May 12 '16 at 21:16
  • The return value of `secItemAdd` is a result code- https://developer.apple.com/library/ios/documentation/Security/Reference/keychainservices/#//apple_ref/doc/uid/TP30000898-CH5g-CJBEABHG – Paulw11 May 12 '16 at 21:21
  • yes...it doesnt give failure description ... – Swapnil May 13 '16 at 17:42

1 Answers1

0

Your problem is in your access group. You're using [[NSBundle mainBundle] bundleIdentifier]. That's not a valid access group. Your access group must begin with your AppID. You can either hard-code this (as they do in the KeychainItemWrapper sample code), or you can query it at runtime.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610