转自: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

  1. Select your app target and click Capabilities tab.
  2. 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 intoSecItemAddSecItemDelete and SecItemCopyMatching functions.

Delete a shared Keychain item

let itemKey = "My key"
let itemValue = "My secretive bee 

如何在多个iOSapp里共享数据相关推荐

  1. Disruptor 线程间共享数据无需竞争

    队列的作用是缓冲 缓冲到 队列的空间里.. 线程间共享数据无需竞争 原文 地址  作者  Trisha   译者:李同杰 LMAX Disruptor 是一个开源的并发框架,并获得2011 Duke' ...

  2. 线程的创建 验证线程之间共享数据 守护线程 线程进程效率对比 锁 死锁 递归锁...

    线程(from threading import Thread):CPU调度的最小单位 线程的两种创建方式:方式一: 1 from threading import Thread 2 def f1(i ...

  3. python—多线程之线程之间共享数据(Queue)

    一.Queue理解 从一个线程向另一个线程发送数据最安全的方式可能就是使用queue库中的队列了.创建一个被多个线程共享的Queue对象,这些线程通过使用put()和get()操作来向队列中添加或者删 ...

  4. DLL入门浅析(5)——使用DLL在进程间共享数据

    在Win16环境中,DLL的全局数据对每个载入它的进程来说都是相同的,因为所有的进程用的都收同一块地址空间:而在Win32环境中,情况却发生了变化,每个进程都有了它自己的地址空间,DLL函数中的代码所 ...

  5. 容器学习 之 共享数据(十六)

    容器与 host 共享数据 我们有两种类型的 data volume,它们均可实现在容器与 host 之间共享数据,但方式有所区别. 对于 bind mount 是非常明确的:直接将要共享的目录 mo ...

  6. Laravel 5 多个视图共享数据的方法

    我们都知道模板一般会用到继承,导航栏就是一个很好的例子,但是导航栏的数据如何共享,比如有个导航的文件叫在view/navigation.blade.php 为了简单一点,文件里只有设置了一个变量 1 ...

  7. C++多线程快速入门(二)共享数据同步以及数据竞争

    目录 std::unique_lock类模板 仅调用一次 线程局部存储 原子变量 往期内容回顾 std::unique_lock类模板 互斥锁保证了线程间的同步,却将并行操作变成了串行操作,对性能有较 ...

  8. Android 里的数据储存

    数据持久化 关于数据储存,这个话题已经被反复讨论过很多次了,我是不建议把网络存储这种方式纳入到数据储存的范围的,因为这个和Android没多少关系,因此就有如下的分类: 本地储存(也称之为数据持久化, ...

  9. Docker精华问答 | 多个 Docker 容器之间共享数据怎么办?

    在计算机技术日新月异的今天, Docker 在国内发展的如火如荼.特别是在一线互联网公司 Docker 的使用是十分普遍的,甚至成为了一些企业面试的加分项,那么今天我们继续关于Docker 的精华问答 ...

  10. python多核cpu_Python中的多核CPU共享数据之协程详解

    一 : 科普一分钟 尽管进程间是独立存在的,不能相互访问彼此的数据,但是在python中却存在进程间的通信方法,来帮助我们可以利用多核CPU也能共享数据. 对于多线程其实也是存在一些缺点的,不是任何场 ...

最新文章

  1. 14级团队学习成果汇报 -- 利用express+socket.io搭建简易版聊天室
  2. Oracle Schema Objects——Index
  3. 【收藏】Linux系统常用命令速查手册(附PDF下载链接)
  4. PHP的CI框架流程基本熟悉
  5. Cookie实现用户登录记住密码,实现自动登录
  6. python计算最大回撤_Python做量化投资评价策略风险 如何计算最大回撤?
  7. 1.x和2.x的区别
  8. 9 10次c语言上机作业答案,第十五次上机作业带答案
  9. Hive sql语句必练50题
  10. web安全day5:DNS部署与安全
  11. ASP .NET中一个可以用来大作文章的地方。
  12. Java 虚拟机启动
  13. 电动汽车蒙特卡洛分析matlab 通过matlab程序编写电动汽车蒙特卡洛模型
  14. matlab需要什么运行库,运行库是什么?常用软件运行库都有哪些?
  15. 多台服务器集群部署方案
  16. 【计算机硬件系统设计(华科)——存储器设计(Logisim 实现)】
  17. Java基础---整理1:JRE+进制+注释+关键字+标识符+变量
  18. windows live messenger 80072eff
  19. 轻快pdf阅读器如何使用
  20. 苹果你深深的伤害了我,还不让我说

热门文章

  1. 操作系统 ucore lab1实验报告
  2. [转贴]风险管理之巴塞尔协议
  3. Android只播放gif动画
  4. 网络营销的4p营销理论
  5. Android简易天气App
  6. 响应式美容美发形象设计艺术教育学校网站织梦模板源码
  7. EXCEL抓取SQL查询数据
  8. Heartbeat高可用软件服务--1.Heartbeat介绍(2)
  9. Python中关于函数的操作
  10. 自制冰箱,冰柜蒸发器和毛细管的速算