iPhone应用中如何获取硬件版本以及系统信息

移动开发 iOS
iPhone应用中如何获取硬件版本以及系统信息是本文要介绍的内容,主要是基于代码来实现硬件版本和系统信息的获取,来看详细内容。

iPhone应用中如何获取硬件版本以及系统信息是本文要介绍的内容,主要是基于代码来实现硬件版本系统信息的获取,来看详细内容。获取iphone的系统信息使用[UIDevice currentDevice],信息如下:

 

  1. [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS  
  2.  
  3. [[UIDevice currentDevice] systemVersion]:系统版本,如4.2.1  
  4.  
  5. [[UIDevice currentDevice] model]:The model of the device,如iPhone或者iPod touch  
  6.  
  7. [[UIDevice currentDevice] uniqueIdentifier]:设备的惟一标识号,deviceID  
  8.  
  9. [[UIDevice currentDevice] name]:设备的名称,如 张三的iPhone  
  10.  
  11. [[UIDevice currentDevice] localizedModel]:The model of the device as a localized string,类似model 
  1. 详见http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html 

但是以上的信息貌似无法得到设备的硬件版本以及系统信息,例如一个iphone3GS,系统升级到了iphone 4。此时使用systemVersion得到的应该是4.x.x,那我们如何知道该设备为iphone3GS呢。网上流传一个方法,经测试应该是有用的。

自定义一个类:

  1. #import <Foundation/Foundation.h> 
  2. @interface UIDeviceHardware : NSObject {     
  3. }  
  4. - (NSString *) platform;  
  5. - (NSString *) platformString;  
  6. @end  
  7. #import "UIDeviceHardware.h"  
  8. #include <sys/types.h> 
  9. #include <sys/sysctl.h> 
  10. @implementation UIDeviceHardware  
  11. - (NSString *) platform{  
  12.     size_t size;  
  13.     sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
  14.     char *machine = malloc(size);  
  15.     sysctlbyname("hw.machine", machine, &size, NULL, 0);  
  16.     NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];  
  17.     free(machine);  
  18.     return platform;  
  19. }  
  20.  
  21. - (NSString *) platformString{  
  22.     NSString *platform = [self platform];  
  23.     if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";  
  24.     if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";  
  25.     if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";  
  26.     if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";  
  27.     if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";  
  28.     if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";  
  29.     if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";  
  30.     if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";  
  31.     if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";  
  32.     if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"])        
  33.   return @"iPhone Simulator";  
  34.     return platform;  
  35. }  
  36. @end 

使用[[[UIDeviceHardware alloc] init] platform]应该就可以得到设备的硬件版本。源码地址:http://download.csdn.net/source/3415689

小结:iPhone应用中如何获取硬件版本以及系统信息的内容介绍完了,希望通过本文的学习鞥读你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2018-07-27 15:50:55

LinuxUbuntu版本

2018-07-30 08:56:03

LinuxUbuntu版本

2011-08-19 14:34:03

iPhone开发

2015-05-25 19:37:17

InxiLinux

2011-08-12 13:35:23

iPhone文件流ASIHTTPRequ

2022-11-06 19:34:53

UbuntuLinux

2015-12-21 13:34:31

LinuxGPU显卡硬件

2010-11-05 13:02:58

内存iPhone

2012-04-26 13:17:56

iPhone应用发布登录银行信息

2009-09-25 10:48:07

Linux硬件信息操作系统

2011-07-28 14:00:45

Ubuntu

2011-08-17 15:10:21

iPhone开发Web视图

2013-03-27 10:32:22

2019-05-24 14:15:30

Linux硬件信息命令

2011-08-02 17:14:41

iPhone应用 UITableVie

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-01 09:50:46

iPhone 获取对象 UIView

2010-07-30 14:28:24

RIP协议

2011-08-02 17:27:06

iPhone应用 剪切技巧

2022-05-27 12:13:58

LinuxLinux 内核
点赞
收藏

51CTO技术栈公众号