利用KeyChain共享数据(唯一标示)
2016-01-11 23:00
519 查看
利用KeyChain共享数据(唯一标示)
下载KeychainItemWrapper
官方demohttps://developer.apple.com/library/ios/samplecode/GenericKeychain/GenericKeychain.zip
导入KeychainItemWrapper
在项目中导入KeychainItemWrapper,添加Security.framework库。
设置KeychainItemWrapper为非arc
TARGETS —> Build Phases —> Compile Sources
标记KeychainItemWrapper为:-fno-objc-arc
添加配置
添加配置有两种,可以添加plist文件或者添加entitlements文件。添加plist文件
以下为官方demo的plist详情:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>keychain-access-groups</key> <array> <string>YOUR_APP_ID_HERE.com.yourcompany.GenericKeychain</string> <string>YOUR_APP_ID_HERE.com.yourcompany.GenericKeychainSuite</string> </array> </dict> </plist>
可从官方demo中看出内容格式为
YOUR_APP_ID_HERE.com.yourcompany.GenericKeychain
例如:
$(AppIdentifierPrefix)com.yourcompany.xxx
配置多个可在这些APP中共享数据。
TARGETS —> Build Settings —> Code Signing Entitlements
配置Entitlements:
$(SRCROOT)/plist在项目中绝对位置/xxxx.plist
例如:
$(SRCROOT)/keychain/KeychainAccessGroups.plist
添加entitlements文件
TARGETS —> Capabilities —> Keychain Sharing
设置Keychain Sharing状态为on
添加Keychain Groups:
com.yourcompany.xxx
设置唯一标示
假设以IDFV作为标示,利用KeyChain可以保证卸载以后仍是原IDFV,实现唯一标示。可以实现多APP使用统一唯一标示。
+(NSString *)getIDFV { KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"IDFV" accessGroup:nil]; NSString *strIDFV = [keychainItem objectForKey:(id)CFBridgingRelease(kSecValueData)]; if (strIDFV.length == 0) { strIDFV = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; [keychainItem setObject:strIDFV forKey:(id)CFBridgingRelease(kSecValueData)]; } return strIDFV; }
相关文章推荐
- BZOJ1786: [Ahoi2008]Pair 配对/1831: [AHOI2008]逆序对
- Paint类(画笔)
- 行为型模式-职责链chain of responsibility
- 软RAID-mdadm折腾小记
- VS 2012 No exports were found that match the constraint 解决办法
- Leetcode——Contains Duplicate
- Leetcode——Contains Duplicate
- HDOJ 2057A + B Again十六进制问题
- Daily Scrum – 1/11
- mailx配置安装
- Selected SVN connector library is not available or cannot be loaded
- rails test provide函数,重构
- leetcode 172: Factorial Trailing Zeroes
- Wireless之无线模块启动AP模式后AP结点搜索不到
- 人工智能之搜索策略-A*算法进阶
- kamailio sip server 开发指南
- AIX-topas命令
- 人工智能之搜索策略-A*算法入门
- Chrome扩展开发(Gmail附件管理助手)系列之〇——概述
- JetBrains注册码计算(IntelliJ IDEA 15.0注册码激活)