How to obtain the hardware version and system information in iPhone applications

Source: Internet
Author: User

IPhoneHow to obtainHardware versionAndSystem InformationIs the content to be introduced in this article, mainly based on codeHardware versionAndSystem InformationTo see the details. ObtainIphoneThe system information of uses [UIDevice currentDevice]. The information is as follows:

 
 
  1. [[UIDevice currentDevice] systemName]: system name, for example, iPhone OS
  2.  
  3. [[UIDevice currentDevice] systemVersion]: system version, for example, 4.2.1
  4.  
  5. [[UIDevice currentDevice] model]: The model of the device, such as iPhone or iPod touch
  6.  
  7. [[UIDevice currentDevice] uniqueIdentifier]: Unique Identifier of the device, deviceID
  8.  
  9. [[UIDevice currentDevice] name]: The device name, for example, Michael's iPhone
  10.  
  11. [[UIDevice currentDevice] localizedModel]: The model of the device as a localized string, similar to model
 
 
  1. See http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

However, the above information does not seem to be able to obtain the hardware version and system information of the device, such as an iphone 3gs. The system is upgraded to iphone 4. In this case, systemVersion is used to get the result 4. x. x. How do we know that the device is iphone3GS. A method has been circulated on the Internet. It should be useful after testing.

Customize a class:

 
 
  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 

Use [[[UIDeviceHardware alloc] init] platform] to obtain the hardware version of the device. Source Code address: http://download.csdn.net/source/3415689

Summary:IPhoneHow to obtainHardware versionAndSystem InformationThe content of this article has been introduced. I hope you can read it through the study tips in this article!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.