头文件
#import <Foundation/Foundation.h>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,
};@interface JDDeviceUtils : NSObject+ (DeviceType)deviceType;@end
.m文件
#import "JDDeviceUtils.h"
#import <sys/utsname.h>@implementation JDDeviceUtils+ (DeviceType)deviceType{struct utsname systemInfo;uname(&systemInfo);NSString *platform = [NSString stringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];//simulatorif ([platform isEqualToString:@"i386"]) return Simulator;if ([platform isEqualToString:@"x86_64"]) return Simulator;//iPhoneif ([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;return Unknown;}