首页 文章

指定访问组时KeychainItemWrapper错误

提问于
浏览
3

很长一段时间以来,我一直使用ARC版的KeychainItemWrapper成功阅读和编写私钥匙项 .

我现在正在努力将我的iOS应用程序转换为使用共享访问组,以便我的2个应用程序可以访问共享相同应用程序前缀的钥匙串项目 . 在功能部分,我添加了钥匙串组“MYAPPPREFIX.MYSHAREDACCESSNAME”

我正在使用这些行将我的变量写入钥匙串组:

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

如果将accessGroup指定为 nil ,则效果很好 . 但是,如果我指定访问组,我会在调试器日志中遇到以下错误:

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

生成的OSStatus错误代码是-25243,我无法追踪到更多信息 .

为了写入共享访问组,我可能还需要做些什么吗?

1 回答

  • 5

    如果它有助于其他人,我能够找出问题所在 . 在Xcode'Capabilities'中我需要省略app id前缀 . 但是,在识别访问组时,需要包含app id前缀 .

    因此,在功能方面,我将一个组命名为“myAccessGroup” .

    在我的代码中,我包含前缀:

    keychainItemWrapper = [[KeychainItemWrapper alloc] initWithIdentifier:key accessGroup:@"xxxxxxxx.myAccessGroup"];
    

相关问题