存贮在keychainQuery 可以统计用户使用情况

-(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 获取手机 唯一标识的更多相关文章

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

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

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

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

  3. iOS获取设备唯一标识的各种方法?IDFA、IDFV、UDID分别是什么含义?

    一.UDID (Unique Device Identifier) UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和 ...

  4. js获取手机唯一标识码

    Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号.厂商等.通过plus.device获取设备信息管理对象. imei: 设备的国际移动设备身份码 imsi: 设备的 ...

  5. Android获取手机唯一码

    大部分安卓手机都可以获取手机唯一码,但是有些手机的厂商却禁止了获取手机唯一码的权限,导致我们不能使用手机唯一码作为标识,但遇到一些必须要填的坑,我们也不能不填,所以使用以下方法来填坑,因此我们使用UU ...

  6. Android 手机上获取物理唯一标识码[转]

    所有添加有谷歌账户的设备可以返回一个 ANDROID_ID 所有的CDMA设备对于 ANDROID_ID 和 TelephonyManager.getDeviceId() 返回相同的值(只要在设置时添 ...

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

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

  8. Android 手机上获取物理唯一标识码

    唯一标识码这东西在网络应用中非常有用,例如检测是否重复注册之类的. import android.provider.Settings.Secure;private String android_id ...

  9. 获取设备唯一标识 uuid(采用第三方库SSKeychain)

    SSKeyChain 下载链接: http://pan.baidu.com/s/1booV3VD 密码: ivdi /** *  获取设备唯一标识 uuid */ +(NSString*) uuid ...

随机推荐

  1. 无法读取配置节"system.web.extensions",因为它缺少节声明

    设置 .Net Framework版本 v2.0.50727 要设置成 v4.0.30319

  2. js hover 下拉框

    <div class="box"> <div class="a f">111111</div> <div class= ...

  3. 35个Redis面试题

    1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库 ...

  4. vue-cli中添加使用less

    在vue-cli中构建的项目是可以使用less的,但是查看package.json可以发现,并没有less相关的插件,所以我们需要自行安装. 第一步:安装 npm install less less- ...

  5. bzoj 3555 企鹅QQ

    https://www.lydsy.com/JudgeOnline/problem.php?id=3555 枚举每一位字符,计算字符两侧的哈希值,然后进行比较,用map或排序记录出与其相同的字符串数量 ...

  6. Sdoi2014 向量集

    题目描述 题解: 码力太差重构之后才$A……$ 首先求向量点积最大很容易想到凸包, 设已知$(x_0,y_0)$,求$(x,y)$满足$(x,y)*(x_0,y_0)>=(x',y')*(x_0 ...

  7. Mybatis 头信息

    在使用IDEA开发中,如果不使用Mybatis-Generator时,那么就需要手写Mapper文件,而在创建xml文件时无法直接创建带有mybatis头信息的mapper文件,这里来记录一下Myba ...

  8. 特殊权限和facl

    目 录 第1章 FACL访问控制    1 1.1 FACL简介    1 1.2 getfacl命令查看acl权限    1 1.3 setfacl设置文件的cal权限    1 1.4 批量添加a ...

  9. laravel 集成 swagger插件

    原文链接:https://medium.com/@mahbubkabir/discovering-swagger-in-laravel-rest-apis-cb0271c8f2 1.composer ...

  10. 【UVA 1636】 (条件概率)

    题链:https://cn.vjudge.net/problem/UVA-1636 题意 给出一把枪的子弹序列,已知开了一枪且无子弹,问下一步的决策是旋转,还是开下一枪 题解 已知开一枪没子弹,下一枪 ...