美文网首页奔跑吧 iOS
IOS获取设备型号

IOS获取设备型号

作者: peterpancn | 来源:发表于2016-06-24 14:26 被阅读0次

    #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

    相关文章

      网友评论

        本文标题:IOS获取设备型号

        本文链接:https://www.haomeiwen.com/subject/frnndttx.html