iOS开发中,获取iOS设备型号

Posted 海豚的信笺

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发中,获取iOS设备型号相关的知识,希望对你有一定的参考价值。

1、首先要导入头文件
  #import <sys/utsname.h>
 
2、代码如下
 
- (NSString *)getDeviceVersionInfo{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *platform = [NSString stringWithFormat:@"%s", systemInfo.machine];
    //    //返回  iPhone iPod iPad
    //    NSString *deviceType = [[UIDevice currentDevice] model];
    return platform;
}
 
- (NSString *)correspondVersion {
    NSString *correspondVersion = [self getDeviceVersionInfo];
    if ([correspondVersion isEqualToString:@"i386"])           [email protected]"Simulator";
    if ([correspondVersion isEqualToString:@"x86_64"])      return @"Simulator";
    if ([correspondVersion isEqualToString:@"iPhone1,1"])   [email protected]"iPhone 1";
    if ([correspondVersion isEqualToString:@"iPhone1,2"])   [email protected]"iPhone 3";
    if ([correspondVersion isEqualToString:@"iPhone2,1"])   [email protected]"iPhone 3S";
    if ([correspondVersion isEqualToString:@"iPhone3,1"] || [correspondVersion isEqualToString:@"iPhone3,2"])       [email protected]"iPhone 4";
    if ([correspondVersion isEqualToString:@"iPhone4,1"])   [email protected]"iPhone 4S";
    if ([correspondVersion isEqualToString:@"iPhone5,1"] || [correspondVersion isEqualToString:@"iPhone5,2"])   return @"iPhone 5";
    if ([correspondVersion isEqualToString:@"iPhone5,3"] || [correspondVersion isEqualToString:@"iPhone5,4"])   return @"iPhone 5C";
    if ([correspondVersion isEqualToString:@"iPhone6,1"] || [correspondVersion isEqualToString:@"iPhone6,2"])   return @"iPhone 5S";
    if ([correspondVersion isEqualToString:@"iPhone7,1"])  return @"iPhone 6";
    if ([correspondVersion isEqualToString:@"iPhone7,2"])  return @"iPhone 6 plus";
    if ([correspondVersion isEqualToString:@"iPhone8,1"])  return @"iPhone 6s";
    if ([correspondVersion isEqualToString:@"iPhone8,2"])  return @"iPhone 6s plus";
    if ([correspondVersion isEqualToString:@"iPhone8,4"])  return @"iPhone SE";
  if ([correspondVersion isEqualToString:@"iPhone9,1"])    return @"iPhone 7 (CDMA)";
  if ([correspondVersion isEqualToString:@"iPhone9,3"])    return @"iPhone 7 (GSM)";
    if ([correspondVersion isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus (CDMA)";
    if ([correspondVersion isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus (GSM)";
   
    //iPod
    if ([correspondVersion isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([correspondVersion isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([correspondVersion isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([correspondVersion isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    if ([correspondVersion isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
 
    //iPad
    if ([correspondVersion isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([correspondVersion isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([correspondVersion isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([correspondVersion isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([correspondVersion isEqualToString:@"iPad2,4"])      return @"iPad 2 (32nm)";
    if ([correspondVersion isEqualToString:@"iPad2,5"])      return @"iPad mini (WiFi)";
    if ([correspondVersion isEqualToString:@"iPad2,6"])      return @"iPad mini (GSM)";
    if ([correspondVersion isEqualToString:@"iPad2,7"])      return @"iPad mini (CDMA)";
    if ([correspondVersion isEqualToString:@"iPad3,1"])      return @"iPad 3(WiFi)";
    if ([correspondVersion isEqualToString:@"iPad3,2"])      return @"iPad 3(CDMA)";
    if ([correspondVersion isEqualToString:@"iPad3,3"])      return @"iPad 3(4G)";
    if ([correspondVersion isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([correspondVersion isEqualToString:@"iPad3,5"])      return @"iPad 4 (4G)";
    if ([correspondVersion isEqualToString:@"iPad3,6"])      return @"iPad 4 (CDMA)";
    if ([correspondVersion isEqualToString:@"iPad4,1"])      return @"iPad Air";
    if ([correspondVersion isEqualToString:@"iPad4,2"])      return @"iPad Air";
    if ([correspondVersion isEqualToString:@"iPad4,3"])      return @"iPad Air";
    if ([correspondVersion isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([correspondVersion isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([correspondVersion isEqualToString:@"i386"])         return @"Simulator";
    if ([correspondVersion isEqualToString:@"x86_64"])       return @"Simulator";
    if ([correspondVersion isEqualToString:@"iPad4,4"]||[correspondVersion isEqualToString:@"iPad4,5"]||[correspondVersion isEqualToString:@"iPad4,6"])      return @"iPad mini 2";
    if ([correspondVersion isEqualToString:@"iPad4,7"]||[correspondVersion isEqualToString:@"iPad4,8"]||[correspondVersion isEqualToString:@"iPad4,9"])      return @"iPad mini 3";
    NSLog(@"您的设备类型是:%@",correspondVersion);
    return correspondVersion;
}

以上是关于iOS开发中,获取iOS设备型号的主要内容,如果未能解决你的问题,请参考以下文章

获取iOS设备的型号

iOS获取设备型号

iOS 获取设备版本型号

iOS-获取Model(设备型号)Version(设备版本)app(程序版本)等

Unity 之 代码获取IOS设备型号 -- 做分辨率适配

iOS获取设备型号设备类型等信息