[iOS]设备型号判断大全(包括iPhoneX,XR,XS,MAX)

头文件

#import 

typedef NS_ENUM(NSInteger,DeviceType) {
    
    Unknown = 0,
    Simulator,
    IPhone_1G,          //基本不用
    IPhone_3G,          //基本不用
    IPhone_3GS,         //基本不用
    IPhone_4,           //基本不用
    IPhone_4s,          //基本不用
    IPhone_5,
    IPhone_5C,
    IPhone_5S,
    IPhone_SE,
    IPhone_6,
    IPhone_6P,
    IPhone_6s,
    IPhone_6s_P,
    IPhone_7,
    IPhone_7P,
    IPhone_8,
    IPhone_8P,
    IPhone_X,
    iPhone_XR,
    iPhone_XS,
    iPhone_XS_Max,
};

@interface JDDeviceUtils : NSObject

+ (DeviceType)deviceType;

@end

.m文件

#import "JDDeviceUtils.h"
#import 

@implementation JDDeviceUtils

+ (DeviceType)deviceType{
   
  
       struct utsname systemInfo;
       uname(&systemInfo);
       NSString *platform = [NSString stringWithCString:systemInfo.machine
                                               encoding:NSUTF8StringEncoding];
       //simulator
       if ([platform isEqualToString:@"i386"])          return Simulator;
       if ([platform isEqualToString:@"x86_64"])        return Simulator;
       
       //iPhone
       if ([platform isEqualToString:@"iPhone1,1"])     return IPhone_1G;
       if ([platform isEqualToString:@"iPhone1,2"])     return IPhone_3G;
       if ([platform isEqualToString:@"iPhone2,1"])     return IPhone_3GS;
       if ([platform isEqualToString:@"iPhone3,1"])     return IPhone_4;
       if ([platform isEqualToString:@"iPhone3,2"])     return IPhone_4;
       if ([platform isEqualToString:@"iPhone4,1"])     return IPhone_4s;
       if ([platform isEqualToString:@"iPhone5,1"])     return IPhone_5;
       if ([platform isEqualToString:@"iPhone5,2"])     return IPhone_5;
       if ([platform isEqualToString:@"iPhone5,3"])     return IPhone_5C;
       if ([platform isEqualToString:@"iPhone5,4"])     return IPhone_5C;
       if ([platform isEqualToString:@"iPhone6,1"])     return IPhone_5S;
       if ([platform isEqualToString:@"iPhone6,2"])     return IPhone_5S;
       if ([platform isEqualToString:@"iPhone7,1"])     return IPhone_6P;
       if ([platform isEqualToString:@"iPhone7,2"])     return IPhone_6;
       if ([platform isEqualToString:@"iPhone8,1"])     return IPhone_6s;
       if ([platform isEqualToString:@"iPhone8,2"])     return IPhone_6s_P;
       if ([platform isEqualToString:@"iPhone8,4"])     return IPhone_SE;
       if ([platform isEqualToString:@"iPhone9,1"])     return IPhone_7;
       if ([platform isEqualToString:@"iPhone9,3"])     return IPhone_7;
       if ([platform isEqualToString:@"iPhone9,2"])     return IPhone_7P;
       if ([platform isEqualToString:@"iPhone9,4"])     return IPhone_7P;
       if ([platform isEqualToString:@"iPhone10,1"])    return IPhone_8;
       if ([platform isEqualToString:@"iPhone10,4"])    return IPhone_8;
       if ([platform isEqualToString:@"iPhone10,2"])    return IPhone_8P;
       if ([platform isEqualToString:@"iPhone10,5"])    return IPhone_8P;
       if ([platform isEqualToString:@"iPhone10,3"])    return IPhone_X;
       if ([platform isEqualToString:@"iPhone10,6"])    return IPhone_X;
       if ([platform isEqualToString:@"iPhone11,8"])    return iPhone_XR;
       if ([platform isEqualToString:@"iPhone11,2"])    return iPhone_XS;
       if ([platform isEqualToString:@"iPhone11,4"] || [platform isEqualToString:@"iPhone11,6"])  return iPhone_XS_Max;

       return Unknown;
   
}

你可能感兴趣的:([iOS]设备型号判断大全(包括iPhoneX,XR,XS,MAX))