ios基本设备信息

开发中总会遇到很多需要查询设备及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 系列
    
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值