iphone – 钥匙串组访问在我现有的应用程序之间共享数据

iphone – 钥匙串组访问在我现有的应用程序之间共享数据,第1张

概述我有很多iOS应用程序在AppStore上。现在,对于下一个版本的应用程序,我想为每个应用程序保留一个数据,以在KeyChain中共享。据我所知,我需要在Apple的KeychainItemWrapper类中提供相同的Keychain访问组。 *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"Any string" acce 我有很多iOS应用程序在AppStore上。现在,对于下一个版本的应用程序,我想为每个应用程序保留一个数据,以在KeyChain中共享。据我所知,我需要在Apple的KeychainItemWrapper类中提供相同的Keychain访问组。

*keychain = [[KeychainItemWrapper alloc] initWithIDentifIEr:@"Any string" accessGroup:<string representing access group>];

我知道自定义URL,它是没有用的,因为我希望数据是持久的。

所有我的应用程序具有不同的捆绑种子ID,我可以从配置门户查看。我知道共享钥匙串访问的主要先决条件是所有的应用程序都有一个共同的捆绑种子ID。

现在我的问题是如何确保在这个场景中我可以使用Keychain在所有这些应用程序之间共享数据?

可以通过配置配置文件门户来更改所有应用程序的捆绑种子ID,而不会对任何功能造成任何损害(尽管我想避免因为有这么多应用程序)。

有没有办法可以在文件中添加所有应用程序的捆绑种子ID,并在项目中构建该文件的所有应用程序来实现?我知道“钥匙串访问组”,我需要创建一个pList文件,并添加所有应用程序的bundle种子ID吗?

欣赏这方面的任何帮助。

解决方法 如果您有不同的捆绑种子ID(捆绑包标识符之前的十个字母数字字符,XXXXXXXXXX.com.company.application中的X),则无法共享访问组。这是对苹果部分的限制,并规避它是不允许的。我建议您找到另一种安全共享数据的解决方案(可能在设备外部,服务器上,而不是iCloud,因为它具有相同的限制)。

有关钥匙串访问组的一般信息:

Since iPhone OS 3.0 it has been possible to share data between a family of applications. This can provIDe a better user experIEnce if you follow the common path of free/premium applications or if you have a set of related applications that need to share some common account settings.

The main pre-requisite for shared keychain access is that all of the applications have a common bundle seed ID. To be clear what this means remember that an App ID consists of two parts:

06000

The bundle seed ID is a unique (within the App Store) ten character string that is generated by Apple when you first create an App ID. The bundle IDentifIEr is generally set to be a reverse domain name string IDentifying your app (e.g. com.yourcompany.appname) and is what you specify in the application Info.pList file in Xcode.

So when you want to create an app that can share keychain access with an existing app you need to make sure that you use the bundle seed ID of the existing app. You do this when you create the new App ID in the iPhone Provisioning Portal. Instead of generating a new value you select the existing value from the List of all your prevIoUs bundle seed IDs.

One caveat,whilst you can create a provisioning profile with a wildcard for the bundle IDentifIEr I have never been able to get shared keychain access working between apps using it. It works fine with fully specifIEd (no wildcard) IDentifIErs. Since a number of other Apple services such as push notifications and in-app purchase also have this restriction maybe it should not be a surprise but I am yet to find this documented for keychain access.

Once you have your provisioning profiles setup with a common bundle seed ID the rest is pretty easy. The first thing you need to do is register the keychain access group you want to use. The keychain access group can be named pretty much anything you want as long as it starts with the bundle seed ID. So for example if I have two applications as follows:

06001

I Could define a common keychain access group as follows:

06002

To enable the application to access this group you need to add an enTitlements pList file to the project using xCode. Use Add -> New file and select the EnTitlements template from the iPhone OS Code Signing section. You can name the file anything you like (e.g. KeychainAccessGroups.pList). In the file add a new array item named keychain-access-groups and create an item in the array with the value of our chosen keychain access group:

Note: Do not change the get-task-allow item that is created by default in the enTitlements file unless you are creating an Ad-Hoc distribution of your app (in which case you should uncheck this option).

This same process should be repeated for all apps that share the bundle seed ID to enable them to access the keychain group. To actually store and retrIEve values from this group requires adding an additional value to the dictionary passed as an argument to the keychain services. Using the example from the prevIoUs post on simple iPhone keychain access the search dictionary gets the following additional item:

06003

One final comment,using a shared keychain access group does not stop you from storing values in an applications private keychain as well. The Apple GenericKeychain example application builds two applications which both store data in a private and group keychain.

资料来源:Use Your Loaf

总结

以上是内存溢出为你收集整理的iphone – 钥匙串组访问在我现有的应用程序之间共享数据全部内容,希望文章能够帮你解决iphone – 钥匙串组访问在我现有的应用程序之间共享数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1086998.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存