How to obtain the hardware version and system information of the iphone

Source: Internet
Author: User

 

Reference:

Http://blog.csdn.net/xiaoguan2008/article/details/6582699

 

 

Use [UIDevice currentDevice] to obtain the system information of the iphone. The information is as follows:

[[UIDevice currentDevice] systemName]: system name, for example, iPhone OS

[[UIDevice currentDevice] systemVersion]: system version, for example, 4.2.1

[[UIDevice currentDevice] model]: The model of the device, such as iPhone or iPod touch

[[UIDevice currentDevice] uniqueIdentifier]: Unique Identifier of the device, deviceID

[[UIDevice currentDevice] name]: The device name, for example, Michael's iPhone

[[UIDevice currentDevice] localizedModel]: The model of the device as a localized string, similar to model

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 information of the device. For example, if an iPhone 3gs is used, 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:

# Import <Foundation/Foundation. h>

@ Interface UIDeviceHardware: NSObject {

}

-(NSString *) platform;

-(NSString *) platformString;

@ End

 

 

# Import "UIDeviceHardware. h"

# Include <sys/types. h>

# Include <sys/sysctl. h>

@ Implementation UIDeviceHardware

-(NSString *) platform {

Size_t size;

Sysctlbyname ("hw. machine", NULL, & size, NULL, 0 );

Char * machine = malloc (size );

Sysctlbyname ("hw. machine", machine, & size, NULL, 0 );

NSString * platform = [NSString stringWithCString: machine encoding: NSUTF8StringEncoding];

Free (machine );

Return platform;

}

 

-(NSString *) platformString {

NSString * platform = [self platform];

If ([platform isEqualToString: @ "iPhone1, 1"]) return @ "iPhone 1G ";

If ([platform isEqualToString: @ "iPhone1, 2"]) return @ "iPhone 3G ";

If ([platform isEqualToString: @ "iPhone2, 1"]) return @ "iPhone 3GS ";

If ([platform isEqualToString: @ "iPhone3, 1"]) return @ "iPhone 4 ";

If ([platform isEqualToString: @ "iPod1, 1"]) return @ "iPod Touch 1G ";

If ([platform isEqualToString: @ "iPod2, 1"]) return @ "iPod Touch 2G ";

If ([platform isEqualToString: @ "iPod3, 1"]) return @ "iPod Touch 3G ";

If ([platform isEqualToString: @ "iPod4, 1"]) return @ "iPod Touch 4G ";

If ([platform isEqualToString: @ "iPad1, 1"]) return @ "iPad ";

If ([platform isEqualToString: @ "i386"] | [platform isEqualToString: @ "x86_64"]) return @ "iPhone Simulator ";

Return platform;

}

@ End

 

Use [[[UIDeviceHardware alloc] init] platform] to obtain the hardware version of the device.

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.