KeychainItemWrapper error when specifying an acces

2019-07-05 05:42发布

For quite some time, I have been successfully reading and writing private keychain items using the ARC version of KeychainItemWrapper.

I'm now working to convert my iOS app to use a shared access group so that the keychain items can be accessed by my 2 apps that share the same app prefix. In the Capabilities section, I've added the keychain group "MYAPPPREFIX.MYSHAREDACCESSNAME"

I'm using these lines to write my variable to the keychain group:

keychainItemWrapper = [[KeychainItemWrapper alloc] initWithIdentifier:key accessGroup:@"MYAPPPREFIX.MYSHAREDACCESSNAME"];
[keychainItemWrapper setObject:value forKey:(__bridge id)(kSecAttrAccount)]; // store the new value in the keychain

If accessGroup is specified as nil, it works great. However, if I specify the access group, I get a crash with the following error in the debugger log:

Assertion failure in -[KeychainItemWrapper writeToKeychain], ..../KeychainItemWrapper.m:329 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'

The resulting OSStatus error code is -25243 which I haven't been able to track down for more information.

Is there something else I might need to do in order to write to the shared access group?

1条回答
地球回转人心会变
2楼-- · 2019-07-05 06:10

In case it helps others, I was able to identify the issue. In Xcode 'Capabilities' I needed to omit the app id prefix. However, the app id prefix needs to be included when identifying the access group.

So, in capabilities, I named a group as 'myAccessGroup'.

In my code, I include the prefix as such:

keychainItemWrapper = [[KeychainItemWrapper alloc] initWithIdentifier:key accessGroup:@"xxxxxxxx.myAccessGroup"];
查看更多
登录 后发表回答