KeychainItemWrapper error when specifying an access group

牧云@^-^@ 提交于 2019-12-10 22:08:15

问题


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:


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"];


来源:https://stackoverflow.com/questions/26286897/keychainitemwrapper-error-when-specifying-an-access-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!