KeychainItemwrapper生成设备唯一标识
来源:互联网 发布:宏源证券交易软件 编辑:程序博客网 时间:2024/05/22 14:55
1.下载苹果官方文档的项目:https://developer.apple.com/library/ios/samplecode/generickeychain/Introduction/Intro.html
2.把工程文件keychainItemWrapper.h/m两个件添加进自己的工程;
3.添加security.framework到工程;
4.测试代码:
+(NSString *) getKeychainIdentifier{ KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"deviceIdentifier" accessGroup:nil];// NSString *username = [wrapper objectForKey:(id)kSecAttrAccount];// NSString *password = [wrapper objectForKey:(id)kSecValueData]; NSString *uniqueIdentifier = [wrapper objectForKey:(id)kSecAttrAccount]; // initially all these are empty// NSLog(@"username - %@", username); // username -// NSLog(@"password - %@", password); // password - NSLog(@"device_identifier:%@",uniqueIdentifier); if ([uniqueIdentifier isEqualToString:@""]) { [wrapper setObject:getuuid() forKey:(id)kSecAttrAccount]; NSLog(@"set uniqueIdentifier."); } uniqueIdentifier = [wrapper objectForKey:(id)kSecAttrAccount]; NSLog(@"uniqueIdentifier:%@", uniqueIdentifier); [wrapper release]; return uniqueIdentifier; //if empty set your credentials// if ( [username isEqualToString:@""] ) {// [wrapper setObject:getuuid() forKey:(id)kSecAttrAccount];// }// if ( [password isEqualToString:@""] ) {// [wrapper setObject:getuuid() forKey:(id)kSecValueData];// } //get the latest credentials - now you have the set values// username = [wrapper objectForKey:(id)kSecAttrAccount];// password = [wrapper objectForKey:(id)kSecValueData]; // NSLog(@"username - %@", username); // username - your username here// NSLog(@"password - %@", password); // password - your password here // reset your keychain items - if needed //[wrapper resetKeychainItem]; } //getDeviceIdentifier//get uuid c style functionNSString * getuuid(){ CFUUIDRef uuid_ref = CFUUIDCreate(NULL); CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref); CFRelease(uuid_ref); NSString *uuid = [NSString stringWithString:(NSString*)uuid_string_ref]; CFRelease(uuid_string_ref); return uuid;
注:raywendlich网站关于keychain的接口封装与实现;
http://www.raywenderlich.com/6475/basic-security-in-ios-5-tutorial-part-1
0 0
- KeychainItemwrapper生成设备唯一标识
- Android 设备唯一标识生成方式
- Android 设备唯一标识生成方式
- 设备的唯一标识
- android设备唯一标识
- 获取设备唯一标识
- ios 设备唯一标识
- 关于设备唯一标识
- 设备唯一标识
- 获取设备唯一标识
- 获取设备唯一标识
- 随即生成唯一标识
- android 手机设备唯一标识
- android 手机设备唯一标识
- android 手机设备唯一标识
- 如何获取设备唯一标识
- android 手机设备唯一标识
- IOS获取设备唯一标识
- git 命令
- Java中子类和父类间的调用关系
- UVa:1424 Salesmen
- websphere6.1 配置sqlserver数据源
- java加载文件的方式
- KeychainItemwrapper生成设备唯一标识
- UVa 305 / POJ 1012 Joseph (如何得到约瑟夫环的下一个位置?)
- 黄河旋风第一天上班
- hdu1754(线段树)
- Linux u-boot加载过程
- ReactiveCocoa 关于在arm64真机运行的问题解决
- 基于Android 平台简易即时通讯的研究与设计
- Python通过文件头来判断文件的真实类型
- vijos1103校门外的树