https://www.jianshu.com/p/ce8cfaf6030e
因为上一次做了用keychain来持久化存储一些特定的数据,后来发现这样做不能保证特别安全。虽然在iOS 系统升级后,钥匙串并不会受到影响,但是在系统还原之后,钥匙串也会跟着重置。另外如果设备损坏不能使用,存储在这个设备钥匙串上的信息也不能够读取出来了。
同时因为公司要求,业务的需要,需要用iCloud来存储一些特定的数据,所以就开始对iCloud的使用进行了初步的学习,只要能上手操作就好~所以就不说那么都的原理,咱们开始动手操作一番吧。
1
去苹果开发者中心添加iCloud容器,也就是iCloud Containers,如图


id格式为 iCloud.+bundle ID ,这个bundle ID不一定是你的工程里的bundle ID,只要你在APP ID里把这个容器添加进去就行了(目前发现是这样没错~)
2
在工程里把iCloud功能打开,将容器添加上去,可能也会自动给你配置

3
用 NSURL *url = [manager URLForUbiquityContainerIdentifier:nil]; 来判断iCloud是否为开启状态,如果url为空,表示iCloud还未开启
4
1.查询iCloud中存储有需要的数据


2.添加数据到iCloud中

3.这是核心方法,上面一切都会调用这个私有方法

附录

大功告成,只要按照我的步骤操作,就没有问题啦~~
PS:还有一个类文件我就不贴出来了~如果有需要的可以点击喜欢后来找我获取⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄