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

  1. iOS 获取手机 唯一标识

    存贮在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. shell timeout

    写脚本的时候,经常需要用到超时控制.看<shell专家编程>时看到一个好例:修改了一下, 1.超过timeout时间还没执行完,则kill进程,发邮件告警: set-xmailSend() ...

  2. 网络环境场景以及模拟工具netem

    网络环境场景包括: 延迟(Lag),把数据包缓存一段时间后再发出,这样能够模拟网络延迟的状况. 掉包(Drop),随机丢弃一些数据. 节流(Throttle),把一小段时间内的数据拦截下来后再在之后的 ...

  3. android ToolBar与DrawerLayout笔记

    通过Android Studio 生成的Nagvition DrawerLayout Activity 自带的布局中的NagvitionView会覆盖ToolBar直接通到statusBar. 但是自 ...

  4. 模拟电路"虚短" & "虚断"

    <虚短 & 虚断> 运算放大器组成的电路五花八门,令人眼花瞭乱,是模拟电路中学习的重点.遍观所有模拟电子技朮的书籍和课程,在介绍运算放大器电路的时候,无非是先给电路来个定性,比如这 ...

  5. 在/etc/password用户名前面加hello,ID前加is

    方法2: #!/bin/sh #set -x file=/etc/passwd while read LINE #for i in `cat $file` do #username=`echo $i| ...

  6. Python之路,Day25-----暂无正在更新中

    Python之路,Day25-----暂无正在更新中

  7. JavaScript--时间显示小插件

    JS调用系统时间,显示在当前页面上,利用DOM操作节点来实现动态刷新 <!DOCTYPE html> <html> <head> <meta charset= ...

  8. ZOJ1463

    题意:给一个括号字符串,求解最少添加的字符能使整个字符串匹配. 输入: s(未匹配的字符串) 输出: S(匹配后的字符串) 思路:绝壁超级坑的一道题,格式我不想说什么了,特坑,然后就是对给定的字符串, ...

  9. cenos6.5 64位下PHP远程连接sql server2008成功案例

    准备工作: 1.sql server2008服务器(开放远程端口,默认为1433,我用的是192.168.1.129) 2.安装好php的centos服务器 步骤: 1.php安装mssql扩展.ce ...

  10. dedecms 使noflag参数及其过滤多个属性的修改方法

    noflag='h' 是代表不包含头条属性的意思,其中flag就是属性, 自定义属性值:头条[h]推荐[c]图片[p]幻灯[f]滚动[s]跳转[j]图文[a]加粗[b]. noflag过滤多个属性的修 ...