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.