How to obtain the hardware name of an ios device
1. If you want to obtain the specific device, the first generation of the product must include
# Import "sys/utsname. h"
Is defined as an auxiliary function:
+ (Std: string) getIosDeviceNameAndGeneration
;
Function implementation:
+ (Std: string) getIosDeviceNameAndGeneration
{
Structutsname systemInfo;
Uname (& systemInfo );
NSLog (@ "% @", [NSStringstringWithCString: systemInfo. machineencoding: NSUTF8StringEncoding]);
Return std: string (systemInfo. machine );
}
The structure of utsname is defined as follows:
Struct utsname {
Char sysname [_ sys_namelen];/* [xsi] Name of OS */
Char nodename [_ sys_namelen];/* [xsi] Name of this network node */
Char release [_ sys_namelen];/* [xsi] Release level */
Char version [_ sys_namelen];/* [xsi] version level */
Char Machine [_ sys_namelen];/* [xsi] hardware type */
};
The machine field is the type of hardware, such as ipod2 and 1. This is the second generation of ipod. The specific device needs to parse the string by yourself.
2. If you only need to obtain the hardware type, such
IPhone,
IPod Touch
IPhone SimulatorAnd so on.
+ (STD: string) getiosdevicename;
Implementation:
+ (STD: string) getiosdevicename
{
Nsstring * nsmodelname = [[uidevicecurrentdevice] model];
Return [nsmodelname
Utf8string];
}
The machineName value is as follows: "iPhone1, 1" => "iPhone 1G ",
"IPhone1, 2" => "iPhone 3G ",
"IPhone E2, 1" => "iPhone 3GS ",
"IPhone3, 1" => "iPhone 4 ",
"IPhone3, 2" => "iPhone 4 Verizon ",
"IPhone3, 3" => "iPhone 4 CDMA ",
"IPhone4, 1" => "iPhone 4 S ",
"IPod1, 1" => "iPod Touch 1G ",
"IPod2, 1" => "iPod Touch 2G ",
"IPod3, 1" => "iPod Touch 3G ",
"IPod4, 1" => "iPod Touch 4G ",
"IPad1, 1" => "iPad ",
"IPad2, 1" => "iPad 2 (WiFi )",
"IPad2, 2" => "iPad 2 (GSM )",
"IPad2, 3" => "iPad 2 (CDMA )",