开发中总会遇到很多需要查询设备及App信息的情况,有时候也是为了更好的用户体验或者为了bug跟踪,可能会需要获取用户的应用信息、系统信息、设备信息。这些信息的获取可以根据不同的设备或者App、系统版本来提供不同的功能或更好的用户体验,或者让开发者能更好的分析用户的问题原因。
因此我查询了很多资料,整理并更新记录起来,为了方便自己日后查询,同时分享给大家,不多说,撸代码吧.
(一)设备及App信息查询
1.获取设备名称
OC代码
1
|
NSString *deviceName = [[UIDevice currentDevice] name];
|
Swift代码
1
|
let deviceName = UIDevice.currentDevice().name
|
2.获取系统版本号
OC代码
1
|
NSString *sysVersion = [[UIDevice currentDevice] systemVersion];
|
Swift代码
1
|
let sysVersion = UIDevice.currentDevice().systemVersion
|
3.获取设备唯一标识符
OC代码
1
|
NSString *deviceUUID = [[[UIDevice currentDevice] identifierForVendor] ;
|
Swift代码
1
|
let deviceUUID = UIDevice.currentDevice().identifierForVendor?.UUIDString
|
4.获取设备型号
OC代码
1
|
NSString *deviceModel = [[UIDevice currentDevice] model];
|
Swift代码
1
|
let deviceModel = UIDevice.currentDevice().model
|
5.获取App相关的信息
OC代码
1
2
3
4
5
6
7
|
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
// 获取App的版本号
NSString *appVersion = [infoDic objectForKey:@
"CFBundleShortVersionString"
];
// 获取App的build版本
NSString *appBuildVersion = [infoDic objectForKey:@
"CFBundleVersion"
];
// 获取App的名称
NSString *appName = [infoDic objectForKey:@
"CFBundleDisplayName"
];
|
Swift代码
1
2
3
4
5
6
7
|
let infoDic = NSBundle.mainBundle().infoDictionary
// 获取App的版本号
let appVersion = infoDic?[
"CFBundleShortVersionString"
]
// 获取App的build版本
let appBuildVersion = infoDic?[
"CFBundleVersion"
]
// 获取App的名称
let appName = infoDic?[
"CFBundleDisplayName"
]
|
(二)iOS获取具体设备型号
OC代码获取iOS设备型号:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// 需要#import + (NSString*)deviceModelName
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
//iPhone 系列
|