如何在 iOS 应用程序之间共享钥匙串数据

发布于 2024-09-30 14:53:12 字数 434 浏览 1 评论 0原文

我正在描述一个问题,我花了相当长的时间才找到答案。

GenericKeychain" 示例在 init 中使用 accessGroup 时,提供一个用于在应用程序之间共享钥匙串数据的包装器是一个良好的开端。

然而,在我的应用程序中实现此操作产生了一个模糊的错误代码(花了很长时间才找到)-25243,这意味着:没有访问控制。

我在 iPad 上运行 Apple 的示例应用程序 (GenericKeychain),却出现了同样的错误。啊?

Apple 的文档是否未能提供实现此目标所需的内容?

I am describing a problem for which it took me quite some time to learn the answer.

The "GenericKeychain" example is a good start at providing a wrapper for sharing keychain data between applications when using the accessGroup in the init.

However, implementing this in my app yielded an obscure error code (which took forever to locate) -25243, which means: No access control.

I ran Apple's example app (GenericKeychain) on my iPad only to get the same error. Huh?

Does Apple's documentation fail to deliver on what is necessary to accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋凉 2024-10-07 14:53:12

经过一些(大量)网络挖掘后,我找到了答案。构建 KeychainItemWrapper 类时使用的访问组还必须在每个应用程序的 Entitlements.plist 文件的“keychain-access-groups”部分中指定。

现在我看到“钥匙串访问组”似乎几乎是显而易见的。然而,我根本不知道要去那里看看。希望这对其他人有帮助。

After some (a lot of) digging throughout the web, I found the answer. The access Group that you use when constructing your KeychainItemWrapper class must ALSO be specified in each of your application's Entitlements.plist file in the "keychain-access-groups" section.

It seems almost obvious now that I see "keychain-access-groups". However, I had no idea to even look there. Hope this helps others.

谷夏 2024-10-07 14:53:12

其实这并不难做到。请按照步骤操作。

App1:

  1. 打开应用程序的目标功能并启用钥匙串共享。
  2. 添加标识符。 (例如:com.example.sharedaccess)
  3. 将“UICKeyChainStore”添加到您的项目中。
  4. 确保您已将团队 ID 添加到您的 App1 项目中。
  5. 将 Security.framework 添加到您的 App1 项目中。
  6. 并将这些代码添加到您需要的地方。

    [UICKeyChainStore setString:@"someValue" forKey:@"someKey" service:@"someService"];
    

App2:

  • 打开您的应用程序的目标功能并启用钥匙串共享。
  • 添加标识符。 (例如:com.example.sharedaccess)
  • 将“UICKeyChainStore”添加到您的项目中。
  • 确保您已将团队 ID 添加到您的 App2 项目中。
  • 将 Security.framework 添加到您的 App2 项目中。
  • 并将这些代码添加到您需要的位置。

    NSString *string = [UICKeyChainStore stringForKey:@"someKey" service:@"someService"];
    
  • 两个项目的 TeamID 应相同。

  • 我在真实的 iPhone 设备上尝试了这些步骤。
  • 我还使用自动iOs Development配置文件尝试了这些步骤。
  • 我的应用程序的捆绑包标识符如下:com.example.app1、com.example.app2。

Actually it's not hard to do. Please follow the steps.

App1:

  1. Open your App's target Capabilities and enable KeyChain Sharing.
  2. Add a identifier. (eg : com.example.sharedaccess)
  3. Add "UICKeyChainStore" to your project.
  4. Be sure you have a team id added to your App1 project.
  5. Add Security.framework to your App1 project.
  6. And add these codes to somewhere you need.

    [UICKeyChainStore setString:@"someValue" forKey:@"someKey" service:@"someService"];
    

App2:

  • Open your App's target Capabilities and enable KeyChain Sharing.
  • Add a identifier. (eg : com.example.sharedaccess)
  • Add "UICKeyChainStore" to your project.
  • Be sure you have a team id added to your App2 project.
  • Add Security.framework to your App2 project.
  • And add these codes to somewhere you need.

    NSString *string = [UICKeyChainStore stringForKey:@"someKey" service:@"someService"];
    
  • Your TeamIDs should be same for both projects.

  • I tried these steps on a real iPhone device.
  • I also tried these steps with Automatic and iOs Development provisioning profile.
  • My apps' bundle identifiers were like that : com.example.app1, com.example.app2.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文