IOS获取设备型号

#include <sys/types.h>

#include <sys/sysctl.h>

取设备:

+ (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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容