如何在多个iOSapp里共享数据
来源:互联网 发布:5.1声道耳机推荐 知乎 编辑:程序博客网 时间:2024/06/05 12:04
转自:http://evgenii.com/blog/sharing-keychain-in-ios/
如有侵犯,请来信oiken@qq.com
使用了KeyAccess这个第三方库保存UUID,原来设计是用了access group,可以多个app共享的,
可惜真机运行时出错了,log提示:
"Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements."
找了资料:https://github.com/kishikawakatsumi/KeychainAccess/issues/52
说了半天,都没搞好,里面的这篇链接(看下文),貌似是能解决的,可是我这里好像是设置不了苹果网页管理那里的group 权限,当前是disable,
想着暂时也不需要多个app共享uuid,就去掉了keyaccess里的参数,只管保证本app能拿回来相同的UUID就好了。
How to share Keychain between iOS apps
Keychain is a secure storage suitable for short bits of sensitive information like passwords or credit card numbers. By default the data saved in one app can not be read in other apps. In most cases this is exactly what we need.
However, sometimes we need to share Keychain items between multiple apps on the same device. For instance, suppose we created two apps where users can log into the same account. It would be nice to have ability to share the login information between these apps. This way the user will only need to log in once in one of the apps.
Fortunately, there is a way to share Keychain items between apps and it can be done by using Keychain Groups. Here is how to do it. The following steps need to be done in all apps where you want to share the Keychain items.
1) Turn on Keychain sharing in Xcode
- Select your app target and click Capabilities tab.
- Turn on the Keychain Sharing capability.
2) Select developer team
3) Specify Keychain group name
Expand the Keychain Sharing capability settings and you will see your app's bundle ID used as the keychain group. You may want to change it to something meaningful to you, for example myKeychainGroup1. Remember the group you entered because you will use it in the code later.
4) App ID Prefix and Keychain group name
Knowing the group name you entered is not enough for sharing the Keychain. You also need to know your App ID Prefix which is added to the beginning of the group name. In order to see how it works click on the.entitlements file and look at the value of the Keychain Access Groups array.
You will notice that the access group value has the form of$(AppIdentifierPrefix)myKeychainGroup1
. The$(AppIdentifierPrefix)
part will be replaced by your App ID Prefix. The problem is that at this stage we probably have no clue what it is, but we will soon find out.
5) What is my App ID Prefix?
The App ID Prefix (also called Team ID) is a unique text identifier associated with your Apple developer account that allows to share keychain and pasteboard items between your apps. Here is how to find what it is:
- Login to you Apple developer account (also known as Member Center)developer.apple.com/account.
- Open the Certificates, Identifiers & Profiles page.
- Tap the App IDs link under Identifiers.
- Tap on an existing app ID or create a new one and you will find an App ID prefix there.
Now you know your App ID prefix and the full Keychain access group name will look like this:
AB123CDE45.myKeychainGroup1
6) Accessing shared Keychain items
We have enabled the Keychain sharing and found out the keychain group name. Now we can delete, add and retrieve shared Keychain items. To work with Keychain you can use one of many Keychain libraries that support access groups (Keychain Swift is one). But here I will show how to do it directly using the built-in Keychain API. The main rule is to pass the access group name with the kSecAttrAccessGroup
query key intoSecItemAdd
, SecItemDelete
and SecItemCopyMatching
functions.
Delete a shared Keychain item
let itemKey = "My key"let itemValue = "My secretive bee 0 0
- 如何在多个iOSapp里共享数据
- 多个session共享数据如何实现
- Android在多个Activity共享数据
- 用内存映射在多个应用程序之间共享数据
- angularJs在多个控制器中共享服务数据
- 如何在同一系统里同时启动多个Tomcat
- 如何在myeclipse里配置多个tomcat
- 如何在同一系统里同时启动多个Tomcat
- 如何在多web服务器共享SESSION数据
- volist时,如何上传N个字段一样的数据以及如何在数据里再次处理
- 如何在模块中共享数据
- [Windows] 如何在进程间共享数据?
- 如何在进程间共享数据
- 如何批量在mysql里添加数据
- 第一个iOSAPP上架经历
- 多个C程序如何访问(共享)同一变量(数据)?
- C++里的共享数据
- 在可执行文件或DLL的多个实例之间共享静态数据
- 网络游戏开发(一)
- seq2seq学习笔记
- Android校招复习资料整理
- [iOS] 图像处理 - 一种高效裁剪图片圆角的算法
- 简单编程题目连载(一)
- 如何在多个iOSapp里共享数据
- 如何去除集合里面的重复元素
- bLue的游戏
- Android开发——Fragment简单示例(一)认识Fragment
- mysql查询正在执行的进程
- Hue安装及测试文档
- Linux下Eclipse的汉化与恢复
- 【Unity】【C#】DateTime时间字符串,月份用英文显示
- Gradle 1.12用户指南翻译——第五十二章. Maven 插件