·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UIDevice获取设备数据以及如何获取应用信息

UIDevice获取设备数据以及如何获取应用信息

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

在IOS的APP的应用开发的过程中,有时候需要自动收集用户设备、系统信息、应用信息等等。 
比如在在app中加入收集用户反馈功能,不仅用户的反馈能够提交到服务器,包括上述信息同时也自动提交到服务器。对用户反馈bug特别有用。

  下面是他们的获取方法: [cpp] view plaincopy
  1. //设备相关信息的获取  
  2.     NSString *strName = [[UIDevice currentDevice] name];  
  3.     NSLog(@"设备名称:%@", strName);  
  4.       
  5.     NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];  
  6.     NSLog(@"设备唯一标识:%@", strId);  
  7.       
  8.     NSString *strSysName = [[UIDevice currentDevice] systemName];  
  9.     NSLog(@"系统名称:%@h", strSysName);  
  10.       
  11.     NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];  
  12.     NSLog(@"系统版本号:%@", strSysVersion);  
  13.       
  14.     NSString *strModel = [[UIDevice currentDevice] model];  
  15.     NSLog(@"设备模式:%@", strModel);  
  16.       
  17.     NSString *strLocModel = [[UIDevice currentDevice] localizedModel];  
  18.     NSLog(@"本地设备模式:%@", strLocModel);  
  19.       
  20.     float version = [[[UIDevice currentDevice] systemVersion] floatValue];  
  21.     NSLog(@"版本号:%f\n", version);  
  22.       
  23.     //app应用相关信息的获取  
  24.     NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];  
  25. //    CFShow(dicInfo);  
  26.       
  27.     NSString *strAppName = [dicInfo objectForKey:@"CFBundleDisplayName"];  
  28.     NSLog(@"App应用名称:%@", strAppName);  
  29.       
  30.     NSString *strAppVersion = [dicInfo objectForKey:@"CFBundleShortVersionString"];  
  31.     NSLog(@"App应用版本:%@", strAppVersion);  
  32.       
  33.     NSString *strAppBuild = [dicInfo objectForKey:@"CFBundleVersion"];  
  34.     NSLog(@"App应用Build版本:%@", strAppBuild);  

但是,在IOS5之后,原来获取iphone的Device Id的接口:[[UIDevice currentDevice] uniqueIdentifier] 被废弃了。 uinqueIdentifier在UIDevice.h中的定义如下: [cpp] view plaincopy
  1. @PRoperty(nonatomic,readonly,retain) NSString    *uniqueIdentifier  NS_DEPRECATED_IOS(2_0, 5_0);  
  2. // a string unique to each device based on various hardware info.  
意思是iOS2.0以上及iOS5.0以下的系统可用,但不建议使用.Apple有可能在ios5.0之后删除该函数. 
经过测试,未越狱的iPhone,系统版本为5.0.1,依然可以获取UDID.。