存贮在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. Spring Data Redis入门示例:程序配置(五)

    单机配置 redis.properties配置 #redis的服务器地址 redis.host=127.0.0.1 #redis的服务端口 redis.port=6379 #客户端超时时间单位是毫秒 ...

  2. C++ new delete(二)

    C++基础遗漏:new和delete 我记得当年学习C++基础的时候,老师曾经告诉我们:一般来说new和delete要成对出现,在使用完new申请的内存后要马上释放.我相信持这种说法的人不止我们老师一 ...

  3. FastNet C++/Python 网络通信库之 协议

    协议可以使用的基础数据类型: UInt8,UInt16,UInt32,UInt64Int8,Int16,Int32,Int64Float,Double,Bool,String [T]  数组,T代表元 ...

  4. InnoDB 事务隔离级别

    InnoDB是一种平衡高可靠性和高性能的通用存储引擎.在MySQL数据库5.5.8版本开始,InnoDB是默认的MySQL存储引擎. InnoDB的主要优势 - 其DML操作遵循ACID,具有提交,回 ...

  5. webpack 之 loader

    loader简介 loader在webpack.config.js中进行配置,配置之后,会自动检测打包过程中引入的文件(import或require),通过test成功匹配被引入的文件名后,会对文件内 ...

  6. 【HDU 6000】Wash(贪心)

    Problem Description Mr.Panda is about to engage in his favourite activity doing laundry! He's brough ...

  7. jquery取当前节点的上级ID

  8. Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!

    D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...

  9. 什么是Etcd?

    文章大部分引至:http://jolestar.com/etcd-architecture/ Etcd 按照官方介绍 Etcd is a distributed, consistent key-val ...

  10. 【贪心+博弈】C. Naming Company

    http://codeforces.com/contest/794/problem/C 题意:A,B两人各有长度为n的字符串,轮流向空字符串C中放字母,A尽可能让字符串字典序小,B尽可能让字符串字典序 ...