史上最全的iOS各种设备信息获取总结
Posted Ven519
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了史上最全的iOS各种设备信息获取总结相关的知识,希望对你有一定的参考价值。
为了统计用户信息、下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息的获取方式:
![](https://image.cha138.com/20221206/61e4d46586d3491481b5b9e158805f68.jpg)
![](https://image.cha138.com/20221206/43224f0c46f14dffa592191e4d0b4a2e.jpg)
GitHub:https://github.com/PengfeiWang666/ios-getClientInfo
-
一行代码就搞定的统一来!
// 这个方法后面会列出来
NSString*deviceName = [selfgetDeviceName];
NSLog(@"设备型号-->%@",deviceName);
NSString*iPhoneName = [UIDevicecurrentDevice].name;
NSLog(@"iPhone名称-->%@",iPhoneName);
NSString*appVerion = [[[NSBundlemainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSLog(@"app版本号-->%@",appVerion);
CGFloatbatteryLevel = [[UIDevicecurrentDevice] batteryLevel];
NSLog(@"电池电量-->%f",batteryLevel);
NSString*localizedModel = [UIDevicecurrentDevice].localizedModel;
NSLog(@"localizedModel-->%@",localizedModel);
NSString*systemName = [UIDevicecurrentDevice].systemName;
NSLog(@"当前系统名称-->%@",systemName);
NSString*systemVersion = [UIDevicecurrentDevice].systemVersion;
NSLog(@"当前系统版本号-->%@",systemVersion);
structutsnamesystemInfo;
uname(&systemInfo);
NSString*device_model = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSLog(@"device_model-->%@",device_model);
// 这个方法后面会单独列出
NSString*macAddress = [selfgetMacAddress];
NSLog(@"macAddress-->%@",macAddress);
// 这个方法后面会单独列出
NSString*deviceIP = [selfgetDeviceIPAddresses];
NSLog(@"deviceIP-->%@",deviceIP);
-
广告位标识符:在同一个设备上的所有App都会取到相同的值,是苹果专门给各广告提供商用来追踪用户而设的,用户可以在 设置|隐私|广告追踪里重置此id的值,或限制此id的使用,故此id有可能会取不到值,但好在Apple默认是允许追踪的,而且一般用户都不知道有这么个设置,所以基本上用来监测推广效果,是戳戳有余了
NSString*idfa = [[[ASIdentifierManagersharedManager] advertisingIdentifier] UUIDString];
NSLog(@"广告位标识符idfa-->%@",idfa);
-
UUID是Universally Unique Identifier的缩写,中文意思是通用唯一识别码。它是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指 定。这样,每个人都可以建立不与其它人冲突的 UUID。在此情况下,就不需考虑数据库建立时的名称重复问题。苹果公司建议使用UUID为应用生成唯一标识字符串
NSString*uuid = [[[UIDevicecurrentDevice] identifierForVendor] UUIDString];
NSLog(@"唯一识别码uuid-->%@",uuid);
-
获取设备型号
// 获取设备型号然后手动转化为对应名称
-(NSString*)getDeviceName
// 需要#import "sys/utsname.h"
#warning 题主呕心沥血总结!!最全面!亲测!全网独此一份!!
structutsnamesystemInfo;
Android--史上最全最完整,获取设备信息获取手机唯一标识