iOS 获取手机 唯一标识
-(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 获取手机 唯一标识的更多相关文章
- iOS 获取手机 唯一标识-b
存贮在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 ...
随机推荐
- vue计算属性computed和methods的区别
computed和methods的区别 在new Vue的配置参数中的computed和methods都可以处理大量的逻辑代码,但是什么时候用哪个属性,要好好区分一下才能做到正确的运用vue. com ...
- Ext 6.5.3 classic版本,自定义实现togglefield开关控件
1,在Ext 6.5.3的classic版中没有提供开关控件,参照modern版中 togglefield开关的实现,继承滑动器(sliderfield),自定义一个开关按钮.支持value绑定和点击 ...
- python 容器 用户注册登录系统
1. 列表和普通变量有什么区别 列表是数据类型,普通变量是用来存储数据的 可以把列表赋值给普通变量 2.存在列表 a = [11, 22, 33], 如何向列表中添加(增)新元素 44 a.appen ...
- (十七)python 3 函数递归
递归函数 即自己调用自己,递归中可以函数自身调用自身,但是使用时类似于条件循环一样,要有递归的终止条件 优点:使用递归时,常常可以让代码更加简洁 缺点:递归会占用比较多的内存,当递归次数比较多时,性能 ...
- Could not find conduit initiator for address:xxxxxxxxx and transport: http://schemas.xmlsoap.org/soap/http
<properties> <cxf.version>3.1.12</cxf.version> </properties> <dependencie ...
- 【HDU 5934】Bomb(强连通缩点)
Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...
- luogu3313 [SDOI2014]旅行
对每一个宗教建一棵线段树,然后树剖搞搞 #include <iostream> #include <cstdio> using namespace std; int n, m, ...
- Linux 下Python2.7解决list打印中文字符问题
在写一个爬取智联招聘数据的爬虫中,将所需内容匹配到后打印出现了utf-8字符,并没有出现中文字符. 例如: >>>listnine = ['梨', '橘子', '苹果', '香蕉'] ...
- String painter(区间DP)
There are two strings A and B with equal length. Both strings are made up of lower case letters. Now ...
- POJ 2288 汉密尔顿回路 DP解决
题目大意: 有n个岛屿,令Vi为岛屿Ci的权值.一条汉密尔顿路径C1,C2,C3...Cn的值为3部分 第一部分,将路径中的岛的权值相加,第二部分将每条边上的(Ci,Cj),加上所有的Vi*Vj 第三 ...