KeychainItemWrapper error when specifying an access group

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?


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"];
链接地址: http://www.djcxy.com/p/83286.html

上一篇: OSStatus错误代码

下一篇: 指定访问组时KeychainItemWrapper错误