获取iOS设备型号,找了一圈发现一般写的都不够全,自己完善了一下。
调用记得加上头文件:
#import
+ (NSString*)deviceString
{
structutsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSStringstringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];
if ([deviceStringisEqualToString:@"iPhone1,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone1G"];
if ([deviceStringisEqualToString:@"iPhone1,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone3G"];
if ([deviceStringisEqualToString:@"iPhone2,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone3GS"];
if ([deviceStringisEqualToString:@"iPhone3,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone4"];
if ([deviceStringisEqualToString:@"iPhone4,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone4S"];
if ([deviceStringisEqualToString:@"iPhone5,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone5"];
if ([deviceStringisEqualToString:@"iPhone5,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone5"];
if ([deviceStringisEqualToString:@"iPhone5,3"]) return [NSStringstringWithFormat:@"%@",@"iPhone5c"];
if ([deviceStringisEqualToString:@"iPhone5,4"]) return [NSStringstringWithFormat:@"%@",@"iPhone5c"];
if ([deviceStringisEqualToString:@"iPhone6,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone5s"];
if ([deviceStringisEqualToString:@"iPhone6,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone5s"];
if ([deviceStringisEqualToString:@"iPhone7,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone6Plus"];
if ([deviceStringisEqualToString:@"iPhone7,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone6"];
if ([deviceStringisEqualToString:@"iPhone8,4"]) return [NSStringstringWithFormat:@"%@",@"iPhone SE"];
if ([deviceStringisEqualToString:@"iPhone8,3"]) return [NSStringstringWithFormat:@"%@",@"iPhone SE"];
if ([deviceStringisEqualToString:@"iPhone8,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone6sPlus"];
if ([deviceStringisEqualToString:@"iPhone8,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone6s"];
if ([deviceStringisEqualToString:@"iPhone9,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone7Plus"];
if ([deviceStringisEqualToString:@"iPhone9,1"]) return [NSStringstringWithFormat:@"%@",@"iPhone7"];
if ([deviceStringisEqualToString:@"iPhone9,4"]) return [NSStringstringWithFormat:@"%@",@"iPhone7Plus"];
if ([deviceStringisEqualToString:@"iPhone9,3"]) return [NSStringstringWithFormat:@"%@",@"iPhone7"];
if ([deviceStringisEqualToString:@"iPhone3,2"]) return [NSStringstringWithFormat:@"%@",@"iPhone4"];
if ([deviceStringisEqualToString:@"iPod1,1"]) return [NSStringstringWithFormat:@"%@",@"iPodTouch1G"];
if ([deviceStringisEqualToString:@"iPod2,1"]) return [NSStringstringWithFormat:@"%@",@"iPodTouch2G"];
if ([deviceStringisEqualToString:@"iPod3,1"]) return [NSStringstringWithFormat:@"%@",@"iPodTouch3G"];
if ([deviceStringisEqualToString:@"iPod4,1"]) return [NSStringstringWithFormat:@"%@",@"iPodTouch4G"];
if ([deviceStringisEqualToString:@"iPad1,1"]) return [NSStringstringWithFormat:@"%@",@"iPad"];
if ([deviceStringisEqualToString:@"iPad2,1"]) return [NSStringstringWithFormat:@"%@",@"iPad2"];
if ([deviceStringisEqualToString:@"iPad2,2"]) return [NSStringstringWithFormat:@"%@",@"iPad2"];
if ([deviceStringisEqualToString:@"iPad2,3"]) return [NSStringstringWithFormat:@"%@",@"iPad2"];
if ([deviceStringisEqualToString:@"iPad2,4"]) return [NSStringstringWithFormat:@"%@",@"iPad 2"];
if ([deviceStringisEqualToString:@"iPad2,5"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini (WiFi)"];
if ([deviceStringisEqualToString:@"iPad2,6"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini"];
if ([deviceStringisEqualToString:@"iPad2,7"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini (GSM+CDMA)"];
if ([deviceStringisEqualToString:@"iPad3,1"]) return [NSStringstringWithFormat:@"%@",@"iPad 3 (WiFi)"];
if ([deviceStringisEqualToString:@"iPad3,2"]) return [NSStringstringWithFormat:@"%@",@"iPad 3 (GSM+CDMA)"];
if ([deviceStringisEqualToString:@"iPad3,3"]) return [NSStringstringWithFormat:@"%@",@"iPad 3"];
if ([deviceStringisEqualToString:@"iPad3,4"]) return [NSStringstringWithFormat:@"%@",@"iPad 4 (WiFi)"];
if ([deviceStringisEqualToString:@"iPad3,5"]) return [NSStringstringWithFormat:@"%@",@"iPad 4"];
if ([deviceStringisEqualToString:@"iPad3,6"]) return [NSStringstringWithFormat:@"%@",@"iPad 4 (GSM+CDMA)"];
if ([deviceStringisEqualToString:@"iPad4,1"]) return [NSStringstringWithFormat:@"%@",@"iPad Air (WiFi)"];
if ([deviceStringisEqualToString:@"iPad4,2"]) return [NSStringstringWithFormat:@"%@",@"iPad Air (Cellular)"];
if ([deviceStringisEqualToString:@"iPad4,4"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 2 (WiFi)"];
if ([deviceStringisEqualToString:@"iPad4,5"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 2 (Cellular)"];
if ([deviceStringisEqualToString:@"iPad4,6"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 2"];
if ([deviceStringisEqualToString:@"iPad4,7"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 3"];
if ([deviceStringisEqualToString:@"iPad4,8"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 3"];
if ([deviceStringisEqualToString:@"iPad4,9"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 3"];
if ([deviceStringisEqualToString:@"iPad5,1"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 4 (WiFi)"];
if ([deviceStringisEqualToString:@"iPad5,2"]) return [NSStringstringWithFormat:@"%@",@"iPad Mini 4 (LTE)"];
if ([deviceStringisEqualToString:@"iPad5,3"]) return [NSStringstringWithFormat:@"%@",@"iPad Air 2"];
if ([deviceStringisEqualToString:@"iPad5,4"]) return [NSStringstringWithFormat:@"%@",@"iPad Air 2"];
if ([deviceStringisEqualToString:@"iPad6,3"]) return [NSStringstringWithFormat:@"%@",@"iPad Pro 9.7"];
if ([deviceStringisEqualToString:@"iPad6,4"]) return [NSStringstringWithFormat:@"%@",@"iPad Pro 9.7"];
if ([deviceStringisEqualToString:@"iPad6,7"]) return [NSStringstringWithFormat:@"%@",@"iPad Pro 12.9"];
if ([deviceStringisEqualToString:@"iPad6,8"]) return [NSStringstringWithFormat:@"%@",@"iPad Pro 12.9"];
if ([deviceStringisEqualToString:@"i386"]) return [NSStringstringWithFormat:@"%@",@"Simulator"];
if ([deviceStringisEqualToString:@"x86_64"]) return [NSStringstringWithFormat:@"%@",@"Simulator"];
return [NSStringstringWithFormat:@"%@",deviceString];
}