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

Source: Internet
Author: User

Use [uidevice
Currentdevice], the information is as follows:

[[Uidevice
Currentdevice] systemname]: system name, such as 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]: 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 is+tostring: @ "i386"] | [Platform
Isequaltostring: @ "x86_64"])
Return @ "iPhone Simulator ";

Return platform;

}

@ End

Use [[[uidevicehardware alloc] init] platform] to obtain the hardware version of the device. (Source Code)

Use [uidevice
Currentdevice], the information is as follows:

[[Uidevice
Currentdevice] systemname]: system name, such as 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]: 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 is+tostring: @ "i386"] | [Platform
Isequaltostring: @ "x86_64"])
Return @ "iPhone Simulator ";

Return platform;

}

@ End

Use [[[uidevicehardware alloc] init] platform] to obtain the hardware version of the device. (Source Code)

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.