iOS 获取手机 唯一标识-b
-(void)gatherMessage{
//采集用户设备信息
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
NSDate *loadDate=[NSDate date];
NSDate *lastData=[userDefaults valueForKey:@"loadForDay"];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YYYY/MM/dd"];
NSString *lastd=[dateFormatter stringFromDate:lastData];
NSString *nowd=[dateFormatter stringFromDate:loadDate];
if (![lastd isEqualToString:nowd]) {
[userDefaults setObject:loadDate forKey:@"loadForDay"];
//获取设备型号
NSString *deviceModel=[CommenData getCurrentDeviceModel];
//identifierForVendor 作为唯一标识
NSString *identifierStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString * const KEY_USERNAME_PASSWORD = @"com.int-yt.kyks.usernamepassword";
NSString * const KEY_PASSWORD = @"com.int-yt.kyks.password";
NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary];
[usernamepasswordKVPairs setObject:identifierStr forKey:KEY_PASSWORD];
NSMutableDictionary *readUserPwd = (NSMutableDictionary *)[CommenData load:KEY_USERNAME_PASSWORD];
if(readUserPwd==nil){
//存
[CommenData save:KEY_USERNAME_PASSWORD data:usernamepasswordKVPairs];
readUserPwd = (NSMutableDictionary *)[CommenData load:KEY_USERNAME_PASSWORD];
}
//调用接口纪录登陆信息
NSString *string= [NSString stringWithFormat:@"%@cdpt/api/uselog?access_token=123&imeiid=%@&mtype=%@&device_platform=2",BaseURLString, [readUserPwd objectForKey:KEY_PASSWORD],deviceModel];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSLog(@"%@",string);
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[operation start];
}
}
//存
+ (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);
}
//获得设备型号
+ (NSString *)getCurrentDeviceModel
{
int mib[2];
size_t len;
char *machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
return platform;
}
iOS 获取手机 唯一标识-b的更多相关文章
- iOS 获取手机 唯一标识
存贮在keychainQuery 可以统计用户使用情况 -(void)gatherMessage{ //采集用户设备信息 NSUserDefaults *userDefaults=[NSUserDef ...
- iOS获取设备唯一标识的8种方法
8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可 ...
- iOS获取设备唯一标识的各种方法?IDFA、IDFV、UDID分别是什么含义?
一.UDID (Unique Device Identifier) UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和 ...
- js获取手机唯一标识码
Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号.厂商等.通过plus.device获取设备信息管理对象. imei: 设备的国际移动设备身份码 imsi: 设备的 ...
- Android获取手机唯一码
大部分安卓手机都可以获取手机唯一码,但是有些手机的厂商却禁止了获取手机唯一码的权限,导致我们不能使用手机唯一码作为标识,但遇到一些必须要填的坑,我们也不能不填,所以使用以下方法来填坑,因此我们使用UU ...
- Android 手机上获取物理唯一标识码[转]
所有添加有谷歌账户的设备可以返回一个 ANDROID_ID 所有的CDMA设备对于 ANDROID_ID 和 TelephonyManager.getDeviceId() 返回相同的值(只要在设置时添 ...
- ios开发——实用技术篇OC篇&获取设备唯一标识
获取设备唯一标识 WWDC 2013已经闭幕,IOS7 Beta随即发布,界面之难看无以言表...,简直就是山寨Android. 更让IOS程序猿悲催的是,设备唯一标识的MAC Address在IOS ...
- Android 手机上获取物理唯一标识码
唯一标识码这东西在网络应用中非常有用,例如检测是否重复注册之类的. import android.provider.Settings.Secure;private String android_id ...
- 获取设备唯一标识 uuid(采用第三方库SSKeychain)
SSKeyChain 下载链接: http://pan.baidu.com/s/1booV3VD 密码: ivdi /** * 获取设备唯一标识 uuid */ +(NSString*) uuid ...
随机推荐
- CentOS squid代理内网主机上网 openVpn配置
- denyhost
1. denyhost 简介及ssh安全 对外提供的服务器,每天都会被恶意扫描,试图暴力穷举密码,达到入侵的目的.从而控***务器,占用资源.网页挂马.垃圾广告.更会影响我们业务的正常使用和数据的安全 ...
- logback 配置详解(一)(转)
转自:http://blog.csdn.net/haidage/article/details/6794509/ 一:根节点<configuration>包含的属性: scan: 当此属性 ...
- NGUI对象跟随鼠标拖拽移动
public Camera WNGUICamera; Vector3 _WoldPosition;//指针的初始位置 // Vector3 _WoldAng; Vector3 WscreenSpace ...
- mac缺少预编译.a问题
在win7的svn提交了coco2d-x 3.0代码,在mac进行更新,用xcode打开工程,编译不成功,一看好多的.a文件全部都是红色的,无法找到文件,一开始不了解coco2d-x的prebuilt ...
- asp.net学习之DataList控件
asp.net学习之DataList控件 DataList控件与Repeater控件一样由模板驱动,与Repeater控件不同的是: DataList控件默认输出是一个HTML表格.DataLis ...
- Django Errors Archive
记录使用 Django 开发中遇到的问题,备用 1. 版本要选好,最好安装上 pip,可以省很多麻烦 2. 如果使用 Postgresql,选 8.1 之后的版本,免去 Retruning 之类的错误 ...
- 初定为EGame
[Q]在纠结到底要用什么方式写博客,是原生态记录框架编写过程(有点所谓的手把手教学的感觉有木有),还是每个模块整合完毕后写分析文章,新手没有写过博客,不知道那种效果好.朋友们给点建议? 这套框架的初衷 ...
- solr建立索引的过程
HttpSolrServer HttpSolrServer继承SolrServer 参考文档:http://my.oschina.net/qige/blog/173008
- JavasScript基数排序
基数排序 91, 46, 85, 15, 92, 35, 31, 22经过基数排序第一次扫描之后, 数字被分配到如下盒子中:Bin 0:Bin 1: 91, 31Bin 2: 92, 22Bin ...