iOS 获取手机 唯一标识-b

存贮在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;

}

时间: 2024-07-31 05:14:40

iOS 获取手机 唯一标识-b的相关文章

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

8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可以改变设备的 UDID),移动网络可以利用 UDID 来识别移动设备. 许多开发者把 UDID 跟用户的真实姓名.密码.住址.其它数据关联起来,网络窥探者会从多个应用收集这些数据,然后顺藤摸瓜得到这个人的许多隐私数据,同时大部分应用确实在频繁传输 UDID 和私人信息. 为了避免集体诉讼,苹果最终决

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

iOS获取设备唯一标识的各种方法?IDFA.IDFV.UDID分别是什么含义? [摘要:1.UDID (Unique Device Identifier) UDID的齐称是Unique Device Identifier,望文生义,它便是苹果IOS装备的独一辨认码,它由40个字符的字母战数字构成.正在良多须要限定] 一.UDID (Unique Device Identifier) UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由

IOS获取设备唯一标识的八种方法

免责声明:本文章来源于其他博客整理 参考:http://www.2cto.com/kf/201308/237648.html 参考:http://www.2cto.com/kf/201311/255684.html 在iOS系统中,获取设备唯一标识的方法有很多: 一.UDID(Unique Device Identifier) UDID的全称是Unique Device Identifier,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和数字组成(越狱的设备通过某些工具可以改变设备的U

(转)iOS获取设备唯一标识码

文/举个栗子wow(简书作者)原文链接:http://www.jianshu.com/p/65c92cd1c0ee著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. “刷优惠券”就是刷美团或者大众这些做首单优惠的App的优惠券,它们为“首单”创造了几个制约因素,其中一个就是设备的唯一性——参加过的不能再参加,这就要获取的设备的唯一标识.这项技能一度使我在大学里吃牛排看电影不要钱.有点跑题,回到正题上.我查阅了一些资料,了解了一下iOS下是如何做到“设备标识的唯一性的”.不得不说iOS

Android应用怎么实现免注册,直接获取手机唯一标识进行登录

============问题描述============ 如题 就是我设计的app登录的时候是直接登录而不需要注册,看到网上说是通过获取Android 手机上物理唯一标识码,见到的都是说通过cpu号和 mac 地址. 想问一下是怎么获取的 能有代码是最好的 ============解决方案1============ 都知道网上查了,为什么不会顺便查下代码呢? http://cache.baiducontent.com/c?m=9d78d513d9901df918b0cf281a16a6375b1

[封装]iOS获取设备唯一标识

现在提供两个方法, 一个用于iOS6, 另一个用于iOS7以上 iOS6: from http://stackoverflow.com/questions/677530/how-can-i-programmatically-get-the-mac-address-of-an-iphone + (NSString *)getMacAddress { int mgmtInfoBase[6]; char *msgBuffer = NULL; size_t length; unsigned char m

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

获取设备唯一标识 WWDC 2013已经闭幕,IOS7 Beta随即发布,界面之难看无以言表...,简直就是山寨Android. 更让IOS程序猿悲催的是,设备唯一标识的MAC Address在IOS7中也失效了. IOS系统中,获取设备唯一标识的方法有很多: 一.UDID(Unique Device Identifier) UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和数字组成. 二.UUID(Univers

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

唯一标识码这东西在网络应用中非常有用,例如检测是否重复注册之类的. import android.provider.Settings.Secure;private String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID); 我们在项目过程中或多或少会使用到设备的唯一识别码,我们希望能够得到一个稳定.可靠的设备唯一识别码.今天我们将介绍几种方式. 1. DEVICE_ID 假

iOS开发日记20-7.0之后获取设备唯一标识

今天博主有一个获取设备唯一标识的需求,遇到了一些困难点,在此和大家分享,希望能够共同进步. 在iOS7.0之前,获取设备唯一标识的方法主要是获取UDID或MAC地址,但是在iOS7.0之后,为了保护用户隐私,苹果把他们都禁止了,使得设备的数据追踪变得越来越难. iOS7.0之后,获取设备唯一标识的方法主要有两种: 1.广告标识符 IDFA 苹果为了完善自己的生态圈,在2010年前后推出了iAd广告网络.那么这个IDFA和这个iAd的关系就不言自喻了.如果不了解广告也没关系,简单来讲,现在的互联网