iOS裝置具體型號獲取

benlue發表於2018-12-24

建立一個UIDevice的分類獲取具體裝置型號

標頭檔案

#import <sys/utsname.h>//獲取裝置型號必須標頭檔案

+(NSString *)deviceModelName {
    
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    //模擬器
    if ([deviceModel isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceModel isEqualToString:@"x86_64"])       return @"Simulator";
    //iPhone 系列
    if ([deviceModel isEqualToString:@"iPhone1,1"])    return @"iPhone_1";
    if ([deviceModel isEqualToString:@"iPhone1,2"])    return @"iPhone_3G";
    if ([deviceModel isEqualToString:@"iPhone2,1"])    return @"iPhone_3GS";
    if ([deviceModel isEqualToString:@"iPhone3,1"])    return @"iPhone_4(GSM)";
    if ([deviceModel isEqualToString:@"iPhone3,2"])    return @"iPhone_4(GSM_AT&T)";
    if ([deviceModel isEqualToString:@"iPhone3,3"])    return @"iPhone_4(CDMA)";
    if ([deviceModel isEqualToString:@"iPhone4,1"])    return @"iPhone_4S";
    if ([deviceModel isEqualToString:@"iPhone4,2"])    return @"iPhone_4S";
    if ([deviceModel isEqualToString:@"iPhone4,3"])    return @"iPhone_4S";
    if ([deviceModel isEqualToString:@"iPhone5,1"])    return @"iPhone_5(GSM)";
    if ([deviceModel isEqualToString:@"iPhone5,2"])    return @"iPhone_5(CDMA)";
    if ([deviceModel isEqualToString:@"iPhone5,3"])    return @"iPhone_5C";
    if ([deviceModel isEqualToString:@"iPhone5,4"])    return @"iPhone_5C";
    if ([deviceModel isEqualToString:@"iPhone6,1"])    return @"iPhone_5S";
    if ([deviceModel isEqualToString:@"iPhone6,2"])    return @"iPhone_5S";
    if ([deviceModel isEqualToString:@"iPhone7,1"])    return @"iPhone_6_Plus";
    if ([deviceModel isEqualToString:@"iPhone7,2"])    return @"iPhone_6";
    if ([deviceModel isEqualToString:@"iPhone8,1"])    return @"iPhone_6S";
    if ([deviceModel isEqualToString:@"iPhone8,2"])    return @"iPhone_6S_Plus";
    if ([deviceModel isEqualToString:@"iPhone8,4"])    return @"iPhone_SE";
    if ([deviceModel isEqualToString:@"iPhone9,1"])    return @"iPhone_7";
    if ([deviceModel isEqualToString:@"iPhone9,3"])    return @"iPhone_7";
    if ([deviceModel isEqualToString:@"iPhone9,2"])    return @"iPhone_7_Plus";
    if ([deviceModel isEqualToString:@"iPhone9,4"])    return @"iPhone_7_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,1"])    return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,4"])    return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,2"])    return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,5"])    return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,3"])    return @"iPhone_X";
    if ([deviceModel isEqualToString:@"iPhone10,6"])    return @"iPhone_X";
    if ([deviceModel isEqualToString:@"iPhone11,2"])    return @"iPhone_XS";
    if ([deviceModel isEqualToString:@"iPhone11,4"])    return @"iPhone_XS_Max";
    if ([deviceModel isEqualToString:@"iPhone11,6"])    return @"iPhone_XS_Max";
    if ([deviceModel isEqualToString:@"iPhone11,8"])    return @"iPhone_XR";
    
    
    //iPad 系列
    if ([deviceModel isEqualToString:@"iPad1,1"])      return @"iPad_1";
    if ([deviceModel isEqualToString:@"iPad1,2"])      return @"iPad_3G";
    if ([deviceModel isEqualToString:@"iPad2,1"])      return @"iPad_2(WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,2"])      return @"iPad_2(GSM)";
    if ([deviceModel isEqualToString:@"iPad2,3"])      return @"iPad_2(CDMA)";
    if ([deviceModel isEqualToString:@"iPad2,4"])      return @"iPad_2(32nm)";
    if ([deviceModel isEqualToString:@"iPad2,5"])      return @"iPad_Mini(WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,6"])      return @"iPad_Mini(GSM)";
    if ([deviceModel isEqualToString:@"iPad2,7"])      return @"iPad_Mini(CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,1"])      return @"iPad_3(WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,2"])      return @"iPad_3(CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,3"])      return @"iPad_3(4G)";
    if ([deviceModel isEqualToString:@"iPad3,4"])      return @"iPad_4(WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,5"])      return @"iPad_4(4G)";
    if ([deviceModel isEqualToString:@"iPad3,6"])      return @"iPad_4(CDMA)";
    if ([deviceModel isEqualToString:@"iPad4,4"])      return @"iPad_Mini_2";
    if ([deviceModel isEqualToString:@"iPad4,5"])      return @"iPad_Mini_2";
    if ([deviceModel isEqualToString:@"iPad4,6"])      return @"iPad_Mini_2";
    if ([deviceModel isEqualToString:@"iPad4,7"])      return @"iPad_Mini_3";
    if ([deviceModel isEqualToString:@"iPad4,8"])      return @"iPad_Mini_3";
    if ([deviceModel isEqualToString:@"iPad4,9"])      return @"iPad_Mini_3";
    
    if ([deviceModel isEqualToString:@"iPad4,1"])      return @"iPad_Air";
    if ([deviceModel isEqualToString:@"iPad4,2"])      return @"iPad_Air";
    if ([deviceModel isEqualToString:@"iPad4,3"])      return @"iPad_Air";
    if ([deviceModel isEqualToString:@"iPad5,1"])      return @"iPad_Mini_4";
    if ([deviceModel isEqualToString:@"iPad5,2"])      return @"iPad_Mini_4";
    if ([deviceModel isEqualToString:@"iPad5,3"])      return @"iPad_Air_2";
    if ([deviceModel isEqualToString:@"iPad5,4"])      return @"iPad_Air_2";
    
    if ([deviceModel isEqualToString:@"iPad6,3"])      return @"iPad_Pro_9.7";
    if ([deviceModel isEqualToString:@"iPad6,4"])      return @"iPad_Pro_9.7";
    if ([deviceModel isEqualToString:@"iPad6,7"])      return @"iPad_Pro_12.9";
    if ([deviceModel isEqualToString:@"iPad6,8"])      return @"iPad_Pro_12.9";
    if ([deviceModel isEqualToString:@"iPad7,1"])      return @"iPad_Pro_12.9";
    if ([deviceModel isEqualToString:@"iPad7,2"])      return @"iPad_Pro_12.9";
    if ([deviceModel isEqualToString:@"iPad7,3"])      return @"iPad_Pro_10.5";
    if ([deviceModel isEqualToString:@"iPad7,4"])      return @"iPad_Pro_10.5";
    
    
    //奇怪? 特別
    if ([deviceModel isEqualToString:@"iPad6,11"])     return @"iPad_5";
    if ([deviceModel isEqualToString:@"iPad6,12"])     return @"iPad_5";
    if ([deviceModel isEqualToString:@"iPad7,5"])      return @"iPad_6";
    if ([deviceModel isEqualToString:@"iPad7,6"])      return @"iPad_6";
    
    //iPod 系列
    if ([deviceModel isEqualToString:@"iPod1,1"])      return @"iPod_Touch_1";
    if ([deviceModel isEqualToString:@"iPod2,1"])      return @"iPod_Touch_2";
    if ([deviceModel isEqualToString:@"iPod3,1"])      return @"iPod_Touch_3";
    if ([deviceModel isEqualToString:@"iPod4,1"])      return @"iPod_Touch_4";
    if ([deviceModel isEqualToString:@"iPod5,1"])      return @"iPod_Touch_5";
    if ([deviceModel isEqualToString:@"iPod7,1"])      return @"iPod_Touch_6";
    
    //Apple TV 系列
    if ([deviceModel isEqualToString:@"AppleTV2,1"])      return @"Apple_TV_2";
    if ([deviceModel isEqualToString:@"AppleTV3,1"])      return @"Apple_TV_3";
    if ([deviceModel isEqualToString:@"AppleTV3,2"])      return @"Apple_TV_3";
    if ([deviceModel isEqualToString:@"AppleTV5,3"])      return @"Apple_TV_4";
    if ([deviceModel isEqualToString:@"AppleTV6,2"])      return @"Apple_TV_4K";

    //Apple Watch
    if ([deviceModel isEqualToString:@"Watch1,1"])      return @"Apple_Watch";
    if ([deviceModel isEqualToString:@"Watch2,6"])      return @"Apple_Watch_Series_1";
    if ([deviceModel isEqualToString:@"Watch2,7"])      return @"Apple_Watch_Series_1";
    if ([deviceModel isEqualToString:@"Watch2,3"])      return @"Apple_Watch_Series_2";
    if ([deviceModel isEqualToString:@"Watch2,4"])      return @"Apple_Watch_Series_2";
    if ([deviceModel isEqualToString:@"Watch3,1"])      return @"Apple_Watch_Series_3";
    if ([deviceModel isEqualToString:@"Watch3,2"])      return @"Apple_Watch_Series_3";
    if ([deviceModel isEqualToString:@"Watch3,3"])      return @"Apple_Watch_Series_3";
    if ([deviceModel isEqualToString:@"Watch3,4"])      return @"Apple_Watch_Series_3";
    if ([deviceModel isEqualToString:@"Watch4,1"])      return @"Apple_Watch_Series_4";
    if ([deviceModel isEqualToString:@"Watch4,2"])      return @"Apple_Watch_Series_4";
    if ([deviceModel isEqualToString:@"Watch4,3"])      return @"Apple_Watch_Series_4";
    if ([deviceModel isEqualToString:@"Watch4,4"])      return @"Apple_Watch_Series_4";
    
    //HomePod
    if ([deviceModel isEqualToString:@"AudioAccessory1,1"])      return @"HomePod";
    
    return deviceModel;
}

複製程式碼

相關文章