设备唯一标识符:
- 1.已禁用-[UIDevice uniqueIdentifier]
苹果总是把用户的隐私看的很重要。-[UIDevice uniqueIdentifier]在iOS5实际在iOS5的时候已经被遗弃了,但是iOS7中已经完全的禁用了它。Xcode5甚至不会允许你编译包含了指引到-[UIDevice uniqueIdentifier]的app。此外,iOS7之前的使用了-[UIDevice uniqueIdentifier] 的app如果在iOS7上运行,它不会返回设备的UUID,而是会返回一串字符串,以FFFFFFFF开头,跟着-[UIDevice identifierForVendor]的十六进制值。
- 2.MAC地址不能再用来设别设备
还有一个生成iOS设备唯一标示符的方法是使用iOS设备的Media Access Control(MAC)地址。一个MAC地址是一个唯一的号码,它是物理网络层级方面分配给网络适配器的。这个地址苹果还有其他的名字,比如说是硬件地址(Hardware Address)或是Wifi地址,都是指同样的东西。
有很多工程和框架都使用这个方法来生成唯一的设备ID。比如说ODIN。然而,苹果并不希望有人通过MAC地址来分辨用户,所以如果你在iOS7系统上查询MAC地址,它现在只会返回02:00:00:00:00:00。
现在苹果明确的表明你应该使用-[UIDevice identifierForVendor]或是-[ASIdentifierManager advertisingIdentifier]来作为你框架和应用的唯一标示符。坦白的来说,应对这些变化也不是那么的难,见以下代码片段:
NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString];
NSString *identifierForAdvertising = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
每种方法都适配一种特别的用法:
identifierForVendor对供应商来说是唯一的一个值,也就是说,由同一个公司发行的的app在相同的设备上运行的时候都会有这个相同的标识符。然而,如果用户删除了这个供应商的app然后再重新安装的话,这个标识符就会不一致。
advertisingIdentifier会返回给在这个设备上所有软件供应商相同的 一个值,所以只能在广告的时候使用。这个值会因为很多情况而有所变化,比如说用户初始化设备的时候便会改变。
-(void) setKeyChainValue
{
KeychainItemWrapper *keyChainItem=[[KeychainItemWrapper alloc]initWithIdentifier:@"TestUUID" accessGroup:@"XXXXXX.h.HelloWorld"];
NSString *strUUID = [keyChainItem objectForKey:(id)kSecValueData];
if (strUUID==nil||[strUUID isEqualToString:@""])
{
[keyChainItem setObject:[self gen_uuid] forKey:(id)kSecValueData];
}
[keyChainItem release];
}
-(NSString *) gen_uuid
{
CFUUIDRef uuid_ref=CFUUIDCreate(nil);
CFStringRef uuid_string_ref=CFUUIDCreateString(nil, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid=[NSString stringWithString:uuid_string_ref];
CFRelease(uuid_string_ref);
return uuid;
}
获取用户信息
-(void)getDeviceInfo{
UIDevice *curDevice = [UIDevice currentDevice];
iPhoneInfoModel *model = [[iPhoneInfoModel alloc] init];
// 用户名称
NSString *deviceInfo = [NSString stringWithFormat:@"%@", curDevice.name];
model.key = @"名称:";
model.value = deviceInfo;
[self.infoArray addObject:model];
// 系统信息
iPhoneInfoModel *systemModel = [[iPhoneInfoModel alloc] init];
NSString *systemInfo = [NSString stringWithFormat:@"%@(%@)", curDevice.systemName, curDevice.systemVersion];
systemModel.key = @"系统:";
systemModel.value = systemInfo;
[self.infoArray addObject:systemModel];
// UUID获取
iPhoneInfoModel *uuidModel = [[iPhoneInfoModel alloc] init];
NSString *uuidInfo = [NSString stringWithFormat:@"%@", [[curDevice identifierForVendor] UUIDString]];
uuidModel.key = @"UUID:";
uuidModel.value = uuidInfo;
[self.infoArray addObject:uuidModel];
}
获取屏幕信息
-(void)getScreenInfo{
NSInteger kHeight = (NSInteger)kScreenHeight;
NSString *screenSize = @"";
NSInteger abs = 1;
switch (kHeight) {
case 480:
screenSize = @"3.5寸";
break;
case 568:
screenSize = @"4.0寸";
abs = 2;
break;
case 667:
screenSize = @"4.7寸";
abs = 2;
break;
case 736:
screenSize = @"5.5寸";
abs = 2;
break;
default:
break;
}
NSString *screenInfo = [NSString stringWithFormat:@"%@(%.0f*%.0f)", screenSize, kScreenWidth * abs, kScreenHeight * abs];
iPhoneInfoModel *model = [[iPhoneInfoModel alloc] init];
model.key = @"屏幕:";
model.value = screenInfo;
[self.infoArray addObject:model];
}
获取运营商信息
-(void)getNetInfo{
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
// 运营商
CTCarrier *carriver = info.subscriberCellularProvider;
NSString *carriverName = [carriver carrierName];
NSString *netInfo = [NSString stringWithFormat:@"%@", carriverName];
iPhoneInfoModel *model = [[iPhoneInfoModel alloc] init];
model.key = @"运营商:";
model.value = netInfo;
[self.infoArray addObject:model];
}
获取电池信息
-(void)getBetaryInfo{
UIDevice *curDevice = [UIDevice currentDevice];
CGFloat batteryLevel = curDevice.batteryLevel * 100;
NSString *batteryState = @"";
if (curDevice.batteryState == UIDeviceBatteryStateCharging) {
batteryState = [NSString stringWithFormat:@"正在充电--%.0f%%", fabs(curDevice.batteryLevel * 100)];
}else if (curDevice.batteryState == UIDeviceBatteryStateFull){
batteryState = [NSString stringWithFormat:@"满电量"];
}else{
batteryState = [NSString stringWithFormat:@"剩余电量 %.0f%%", fabs(curDevice.batteryLevel * 100)];
}
iPhoneInfoModel *model = [[iPhoneInfoModel alloc] init];
model.key = @"电池:";
model.value = batteryState;
[self.infoArray addObject:model];
}
获取内存信息
-(void)getMemInfo{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
double total = 0.0;
double avalible = 0.0;
if (kernReturn == KERN_SUCCESS) {
total = vm_page_size * (vmStats.free_count + vmStats.active_count + vmStats.inactive_count + vmStats.wire_count) / 1024 / 1024.0;
avalible = (vm_page_size * vmStats.free_count) / 1024 / 1024.0;
}
NSString *memInfo = [NSString stringWithFormat:@"%.2fM", avalible];
iPhoneInfoModel *model = [[iPhoneInfoModel alloc] init];
model.key = @"可用内存:";
model.value = memInfo;
[self.infoArray addObject:model];
}
设备信息汇总:
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
NSString*appName =[infoDict objectForKey:@"CFBundleDisplayName"];
NSString*text =[NSString stringWithFormat:@"%@ %@",appName,versionNum];
手机序列号
NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"手机序列号: %@",identifierNumber);
手机别名: 用户定义的名称
NSString* userPhoneName = [[UIDevice currentDevice] name];
NSLog(@"手机别名: %@", userPhoneName);
设备名称
NSString* deviceName = [[UIDevice currentDevice] systemName];
NSLog(@"设备名称: %@",deviceName );
手机系统版本
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@"手机系统版本: %@", phoneVersion);
手机型号
NSString* phoneModel = [[UIDevice currentDevice] model];
NSLog(@"手机型号: %@",phoneModel );
地方型号 (国际化区域名称)
NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel];
NSLog(@"国际化区域名称: %@",localPhoneModel );
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
当前应用名称
NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
NSLog(@"当前应用名称:%@",appCurName);
当前应用软件版本 比如:1.0.1
NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSLog(@"当前应用软件版本:%@",appCurVersion);
当前应用版本号码 int类型
NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
NSLog(@"当前应用版本号码:%@",appCurVersionNum);
参考文章:http://www.jianshu.com/p/b83b0240bd0e
微信号:
clpaial10201119(Q Q:2211523682)
微博WB:
http://weibo.com/u/3288975567?is_hot=1