为了统计用户信息、下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息的获取方式:
直接上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 // 这个方法后面会列出来
NSString *deviceName = [self getDeviceName];
NSLog(@"设备型号-->%@", deviceName);
NSString *iPhoneName = [UIDevice currentDevice].name;
NSLog(@"iPhone名称-->%@", iPhoneName);
NSString *appVerion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSLog(@"app版本号-->%@", appVerion);
CGFloat batteryLevel = [[UIDevice currentDevice] batteryLevel];
NSLog(@"电池电量-->%f", batteryLevel);
NSString *localizedModel = [UIDevice currentDevice].localizedModel;
NSLog(@"localizedModel-->%@", localizedModel);
NSString *systemName = [UIDevice currentDevice].systemName;
NSLog(@"当前系统名称-->%@", systemName);
NSString *systemVersion = [UIDevice currentDevice].systemVersion;
NSLog(@"当前系统版本号-->%@", systemVersion);
struct utsname systemInfo;
uname(&systemInfo);
NSString *device_model = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSLog(@"device_model-->%@", device_model);
// 这个方法后面会单独列出
NSString *macAddress = [self getMacAddress];
NSLog(@"macAddress-->%@", macAddress);
// 这个方法后面会单独列出
NSString *deviceIP = [self getDeviceIPAddresses];
NSLog(@"deviceIP-->%@", deviceIP);
// 设备上次重启的时间
NSTimeInterval time = [[NSProcessInfo processInfo] systemUptime];
NSDate *lastRestartDate = [[NSDate alloc] initWithTimeIntervalSinceNow:(0 - time)];
广告位标识符
在同一个设备上的所有App都会取到相同的值,是苹果专门给各广告提供商用来追踪用户而设的,用户可以在 设置|隐私|广告追踪里重置此id的值,或限制此id的使用,故此id有可能会取不到值,但好在Apple默认是允许追踪的,而且一般用户都不知道有这么个设置,所以基本上用来监测推广效果,是戳戳有余了。1
2NSString *idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
NSLog(@"广告位标识符idfa-->%@", idfa);
UUID
是Universally Unique Identifier的缩写,中文意思是通用唯一识别码。它是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指 定。这样,每个人都可以建立不与其它人冲突的 UUID。在此情况下,就不需考虑数据库建立时的名称重复问题。苹果公司建议使用UUID为应用生成唯一标识字符串。
1 | NSString *uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; |
获取设备型号
1 | // 需要#import "sys/utsname.h" |
获取 iPhone 设备颜色/外壳颜色
1 | #warning 该方法是私有API,上线会被拒 |
mac 地址
1 | - (NSString *)getMacAddress { |
IP地址
1 | - (NSString *)getDeviceIPAddresses { |
CPU
1 | // CPU总数目 |
Disk磁盘空间
1 | // 获取磁盘总空间 |
Memory内存相关数据
1 | // 系统总内存空间 |
作者:si1ence
链接:https://www.jianshu.com/p/b23016bb97af
來源:简书