iOS运用keychain   结合[[[UIDevice currentDevice] identifierForVendor] UUIDString]
取得设备唯一标识 NSString *identifierStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString]
NSString * const KEY_USERNAME_PASSWORD = @"com.snda.app.usernamepassword";
NSString * const KEY_PASSWORD = @"com.snda.app.password";
NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary];
[usernamepasswordKVPairs setObject:identifierStr forKey:KEY_PASSWORD]; //存
[ViewController save:KEY_USERNAME_PASSWORD data:usernamepasswordKVPairs]; NSMutableDictionary *readUserPwd = (NSMutableDictionary *)[ViewController load:KEY_USERNAME_PASSWORD];
NSLog(@"%@",readUserPwd); //存
+ (void)save:(NSString *)service data:(id)data {
//Get search dictionary
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
//Delete old item before add new item
SecItemDelete((__bridge CFDictionaryRef)keychainQuery);
//Add new object to search dictionary(Attention:the data format)
[keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(__bridge id)kSecValueData];
//Add item to keychain with the search dictionary
SecItemAdd((__bridge CFDictionaryRef)keychainQuery, NULL);
} + (NSMutableDictionary *)getKeychainQuery:(NSString *)service {
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass,
service, (__bridge id)kSecAttrService,
service, (__bridge id)kSecAttrAccount,
(__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible,
nil];
} //取
+ (id)load:(NSString *)service {
id ret = nil;
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
//Configure the search setting
//Since in our simple case we are expecting only a single attribute to be returned (the password) we can set the attribute kSecReturnData to kCFBooleanTrue
[keychainQuery setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
[keychainQuery setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
CFDataRef keyData = NULL;
if (SecItemCopyMatching((__bridge CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {
@try {
ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];
} @catch (NSException *e) {
NSLog(@"Unarchive of %@ failed: %@", service, e);
} @finally {
}
}
if (keyData)
CFRelease(keyData);
return ret;
} + (void)delete:(NSString *)service {
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
SecItemDelete((__bridge CFDictionaryRef)keychainQuery);
}

iOS运用keychain 把identifierForVendor当成唯一标识。替换advertisingIdentifier的更多相关文章

  1. 【IOS工具类】获得设备唯一标识(兼容IOS5,6,7)

    UIDevice+IdentifierAddition.h: #import <Foundation/Foundation.h> @interface UIDevice (Identifi ...

  2. ios开发——实用技术篇OC篇&获取设备唯一标识

    获取设备唯一标识 WWDC 2013已经闭幕,IOS7 Beta随即发布,界面之难看无以言表...,简直就是山寨Android. 更让IOS程序猿悲催的是,设备唯一标识的MAC Address在IOS ...

  3. iOS 获取手机 唯一标识-b

    存贮在keychainQuery 可以统计用户使用情况 -(void)gatherMessage{ //采集用户设备信息 NSUserDefaults *userDefaults=[NSUserDef ...

  4. iOS 获取手机 唯一标识

    存贮在keychainQuery 可以统计用户使用情况 -(void)gatherMessage{ //采集用户设备信息 NSUserDefaults *userDefaults=[NSUserDef ...

  5. IOS 用keychain(钥匙串)保存用户名和密码

    IOS系统中,获取设备唯一标识的方法有很多: 一.UDID(Unique Device Identifier) UDID的全称是Unique Device Identifier,顾名思义,它就是苹果I ...

  6. IOS7如何获取设备唯一标识

    WWDC 2013已经闭幕,IOS7 Beta随即发布,界面之难看无以言表...,简直就是山寨Android. 更让IOS程序猿悲催的是,设备唯一标识的MAC Address在IOS7中也失效了. I ...

  7. iOS获取设备唯一标识的8种方法

    8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可 ...

  8. iOS设备唯一标识的前世今生

    设备唯一标识 估计很多开发都有被要求过获取一下设备的唯一标识,获取设备的唯一标识经常使用在我们做统计或者是在保证一台设备登录亦或者是做IM的时候可能会考虑去使用它,这一次在自己的需求当中就有一个&qu ...

  9. ios设备唯一标识获取策略

    In iOS 7 and later, if you ask for the MAC address of an iOS device, the system returns the value 02 ...

随机推荐

  1. 用C扩展Python2

    参考 python扩展实现方法--python与c混和编程 编写Python扩展(Extending Python with C or C++) https://docs.python.org/2.7 ...

  2. MongoDB C# 驱动的各种版本下载地址

    https://github.com/mongodb/mongo-csharp-driver/releases

  3. What is the largest TCP/IP network port number allowable for IPv4

    69 down vote The largest port number is an unsigned short 2^16-1: 65535 A registered port is one ass ...

  4. 咏南Mormot中间件接口

    咏南Mormot中间件接口 只使用了MORMOT的HTTPS.SYS作为通讯,数据引擎使用FIREDAC,数据序列/还原是自行封装. 客户端支持FDMemeTable和ClientDataSet数据集 ...

  5. mormot中间件成功匹配客户端FDMemTable和ClientDataSet

    mormot中间件成功匹配客户端FDMemTable和ClientDataSet

  6. Linux下eclipse编译C/C++程序遇到 undefined reference to `pthread_create'的异常解决办法

    解决方法:右键点击的当前project—>properties—>C/C++ Build—>Settings—>Tool Settings选项卡—>GCC C Linke ...

  7. Android上的单元测试

    Android上的单元测试 http://www.sina.com.cn  2009年12月04日 16:07  IT168.com [IT168 技术文档]任何程序的开发都离不开单元测试来保证其健壮 ...

  8. DotNetty 学习

    [转载]http://www.cnblogs.com/littlegod/p/7699482.html DotNetty的学习是带着如下这些问题展开: 1. Socket基础框架方案: 通信模式:异步 ...

  9. 数据访问:Implementing Efficient Transactions

    An OLTP scenario is characterized by a large number of concurrent operations that create, update, an ...

  10. ASP.NET MVC:模块化/插件式文章汇总

    方案 Shazwazza | Developing a plugin framework in ASP.NET MVC with medium trust 基于ASP.NET MVC3 Razor的模 ...