IOS獲取設(shè)備型號

#include <sys/types.h>

#include <sys/sysctl.h>

取設(shè)備:

+ (NSString *)hardwareFamily {

? ? ? ? NSString *deviceName = [UIDevice currentDevice].name;

? ? ? ? if ([deviceName hasPrefix:@"iPhone"]) {return @"iPhone";}

? ? ? ? else if ([deviceName hasPrefix:@"iPad"]) {return @"iPad";}

? ? ? ? else if ([deviceName hasPrefix:@"iPod"]) {return @"iPodTouch";}

? ? ? ? return @"Unknown";

}

取具體型號:

+ (NSString *)hardwareIdentifier {

? ? ? ? NSString * hardware;

? ? ? ? size_t size = 100;

? ? ? ? char *hw_machine = malloc(size);

? ? ? ? int name[] = {CTL_HW,HW_MACHINE};

? ? ? ? sysctl(name, 2, hw_machine, &size, NULL, 0);

? ? ? ? hardware = [NSString stringWithUTF8String:hw_machine];

? ? ? ? free(hw_machine);

? ? ? ? return hardware;

}

The result should be:

@"iPhone1,1" ? ?on iPhone?

@"iPhone1,2" ? ?on iPhone_3G

@"iPhone1,2*" ?on iPhone_3G_China

@"iPhone2,1" ? ?on iPhone_3GS

@"iPhone2,1*" ? on iPhone_3GS_China

@"iPhone3,1" ? ? on iPhone_4_GSM

@"iPhone3,2" ? ? on iPhone_4_GSM_2012

@"iPhone3,3" ? ? on iPhone_4_CDMA

@"iPhone4,1"? ? on iPhone_4S

@"iPhone4,1*" ? on iPhone_4S_China

@"iPhone5,1" ? ?on iPhone_5_GSM

@"iPhone5,2" ? ?on iPhone_5_Global

@"iPhone5,3" ? ?on iPhone_5C_GSM

@"iPhone5,4"? ? on iPhone_5C_Global

@"iPhone6,1"? ? on iPhone_5S_GSM

@"iPhone6,2"? ? on iPhone_5S_Global

@"iPhone7,1*"? on iPhone_6Plus_China

@"iPhone7,1"? ? on iPhone_6Plus

@"iPhone7,2*" ? on iPhone_6_China

@"iPhone7,2"? ? on iPhone_6

@"iPad1,1"; ? ? ? on iPad

@"iPad1,2" ? ? ? ?on iPad_Cellular

@"iPad2,1"? ? ? ? on iPad_2_WiFi

@"iPad2,2"? ? ? ? on iPad_2_GSM

@"iPad2,3"? ? ? ? on iPad_2_CDMA

@"iPad2,4"? ? ? ? on iPad_2_MID_2012

@"iPad2,5"? ? ? ? on iPad_Mini_WiFi

@"iPad2,6" ? ? ? ?on iPad_Mini_GSM

@"iPad2,7" ? ? ? ?on iPad_Mini_Global

@"iPad3,1" ? ? ? ?on iPad_3_WiFi

@"iPad3,2" ? ? ? ?on iPad_3_CDMA

@"iPad3,3"? ? ? ? on iPad_3_GSM

@"iPad3,4"? ? ? ? on iPad_4_WiFi

@"iPad3,5" ? ? ? ?on iPad_4_GSM

@"iPad3,6" ? ? ? ?on iPad_4_Global

@"iPad4,1"? ? ? ? on iPad_Air_WiFi

@"iPad4,2"? ? ? ? on iPad_Air_Cellular

@"iPad4,3"? ? ? ? on iPad_Air_China

@"iPad5,3"? ? ? ? on iPad_Air_2_WiFi

@"iPad5,4"? ? ? ? on iPad_Air_2_Cellular

@"iPad4,4"? ? ? ? on iPad_Mini_Retina_WiFi

@"iPad4,5"? ? ? ? on iPad_Mini_Retina_Cellular

@"iPad4,6" ? ? ? ?on iPad_Mini_Retina_China

@"iPad4,7"? ? ? ? on iPad_Mini_3_WiFi

@"iPad4,8" ? ? ? ?on iPad_Mini_3_Cellular

@"iPod1,1"? ? ? ? on iPodTouch_1G

@"iPod2,1"? ? ? ? on iPodTouch_2G

@"iPod3,1"? ? ? ? on iPodTouch_3G

@"iPod4,1"? ? ? ? on iPodTouch_4G

@"iPod5,1"? ? ? ? on iPodTouch_5G

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容