为了统计用户信息、下发广告,服务器端往往需要手机用户设备及app的各种信息,整理一下各种信息的获取方式:
设备型号
1 | // 获取设备型号然后手动转化为对应名称 |
iPhone名称
1 | [UIDevice currentDevice].name; |
app版本号
1 | [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; |
电池电量
1 | [[UIDevice currentDevice] batteryLevel]; |
localizedModel
1 | [UIDevice currentDevice].localizedModel; |
当前系统名称
1 | [UIDevice currentDevice].systemName; |
当前系统版本号
1 | [UIDevice currentDevice].systemVersion; |
device_model
1 | struct utsname systemInfo; |
mac 地址
1 | - (NSString *)getMacAddress { |
IP 地址
1 | - (NSString *)getDeviceIPAddresses { |
设备上次重启的时间
1 | NSTimeInterval time = [[NSProcessInfo processInfo] systemUptime]; |
广告位标识符
在同一个设备上的所有App都会取到相同的值,是苹果专门给各广告提供商用来追踪用户而设的,用户可以在 设置 |
隐私 |
广告追踪里重置此id的值,或限制此id的使用,故此id有可能会取不到值,但好在Apple默认是允许追踪的,而且一般用户都不知道有这么个设置,所以基本上用来监测推广效果,是戳戳有余了
1 | NSString *idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; |
UUID
通用唯一识别码。它是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指 定。这样,每个人都可以建立不与其它人冲突的 UUID。在此情况下,就不需考虑数据库建立时的名称重复问题。苹果公司建议使用UUID为应用生成唯一标识字符串。1
2NSString *uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSLog(@"唯一识别码uuid-->%@", uuid);
CPU
1 | // CPU总数目 |
Disk 磁盘
1 | // 获取磁盘总空间 |
内存
1 | // 系统总内存空间 |