iOS获取设备型号和App版本号等信息

  1.  // 获取当前App的基本信息字典 
  2.  NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
  3.  //app名称  
  4.  NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];  
  5.  // app版本  
  6.  NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];  
  7.  // app build版本  
  8.  NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];  
  9.  //手机序列号  
  10.  NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier];  
  11.  //手机别名: 用户定义的名称  
  12.  NSString* userPhoneName = [[UIDevice currentDevice] name];  
  13.  //设备名称  
  14.  NSString* deviceName = [[UIDevice currentDevice] systemName];  
  15.  //手机系统版本  
  16.  NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];   
  17.  //手机型号  
  18.  NSString* phoneModel = [[UIDevice currentDevice] model];  
  19.  //地方型号  (国际化区域名称)  
  20.  NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel];  

 

iOS开发过程中,有时候为了更好的用户体验或者为了bug跟踪,可能会需要获取用户的应用信息、系统信息、设备信息。这些信息的获取可以根据不同的设备或者App、系统版本来提供不同的功能或更好的用户体验,或者让开发者能更好的分析用户的问题原因。

你说不要啰嗦了:Talk is cheap, show me the code!

好的,code来了:

  1. 获取设备名称
    OC代码
    NSString *deviceName = [[UIDevice currentDevice] name];
    Swift代码
    let deviceName = UIDevice.currentDevice().name
  2. 获取系统版本号
    OC代码
    NSString *sysVersion = [[UIDevice currentDevice] systemVersion];
    Swift代码
    let sysVersion = UIDevice.currentDevice().systemVersion
  3. 获取设备唯一标识符
    OC代码
    NSString *deviceUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    Swift代码
    let deviceUUID = UIDevice.currentDevice().identifierForVendor?.UUIDString
  4. 获取设备的型号
    OC代码
    NSString *deviceModel = [[UIDevice currentDevice] model];
    Swift代码
    let deviceModel = UIDevice.currentDevice().model
  5. 获取App相关的信息
    OC代码
     NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

  6. // 获取App的版本号
  7. NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

  8. // 获取App的build版本
  9. NSString *appBuildVersion = [infoDic objectForKey:@"CFBundleVersion"];

  10. // 获取App的名称
  11. NSString *appName = [infoDic objectForKey:@"CFBundleDisplayName"];

 

 


  1. Swift代码
     let infoDic = NSBundle.mainBundle().infoDictionary

  2. // 获取App的版本号
  3. let appVersion = infoDic?["CFBundleShortVersionString"]

  4. // 获取App的build版本
  5. let appBuildVersion = infoDic?["CFBundleVersion"]

  6. // 获取App的名称
  7. let appName = infoDic?["CFBundleDisplayName"]

 

 



有些人可能会说了:“裤子都脱了,你就给我看这个!看你之前写的博客还能看点儿干货,今天第一篇就写着么个玩意儿?尤其是获取设备型号那个,获取出来一个iPhone,你确定不是在逗我吧?”

看官别急,其实这次最主要的就是来分享获取设备型号的方法的,因为我看国内还很少有Swift写的一些东西,也不知道是不是因为我没有找到,就想自己写出来给大家分享,顺便做个笔记。

你会说:获取设备型号比较麻烦,又用的是C语言的一些东西,比较麻烦,而且还得记住所有设备版本号例如:iPhone8,2,实在是记不住啊。当然不用记住,用的时候拷过来就行了,因为我也记不住

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值