1.IOS 获取最新设备型号方法
列表最新对照表:http://theiphonewiki.com/wiki/Models
方法:
#import “sys/utsname.h”
struct utsname systemInfo; uname(&systemInfo); NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
这样得到的 deviceString 是iPhone5,2 的设备号,根据对照表可以获取到当前手机型号。
完整函数:
1 struct utsname systemInfo; 2 uname(&systemInfo); 3 NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; 4 5 NSArray *modelArray = @[ 6 7 @"i386", @"x86_64", 8 9 @"iPhone1,1", 10 @"iPhone1,2", 11 @"iPhone2,1", 12 @"iPhone3,1", 13 @"iPhone3,2", 14 @"iPhone3,3", 15 @"iPhone4,1", 16 @"iPhone5,1", 17 @"iPhone5,2", 18 @"iPhone5,3", 19 @"iPhone5,4", 20 @"iPhone6,1", 21 @"iPhone6,2", 22 23 @"iPod1,1", 24 @"iPod2,1", 25 @"iPod3,1", 26 @"iPod4,1", 27 @"iPod5,1", 28 29 @"iPad1,1", 30 @"iPad2,1", 31 @"iPad2,2", 32 @"iPad2,3", 33 @"iPad2,4", 34 @"iPad3,1", 35 @"iPad3,2", 36 @"iPad3,3", 37 @"iPad3,4", 38 @"iPad3,5", 39 @"iPad3,6", 40 41 @"iPad2,5", 42 @"iPad2,6", 43 @"iPad2,7", 44 ]; 45 NSArray *modelNameArray = @[ 46 47 @"iPhone Simulator", @"iPhone Simulator", 48 49 @"iPhone 2G", 50 @"iPhone 3G", 51 @"iPhone 3GS", 52 @"iPhone 4(GSM)", 53 @"iPhone 4(GSM Rev A)", 54 @"iPhone 4(CDMA)", 55 @"iPhone 4S", 56 @"iPhone 5(GSM)", 57 @"iPhone 5(GSM+CDMA)", 58 @"iPhone 5c(GSM)", 59 @"iPhone 5c(Global)", 60 @"iphone 5s(GSM)", 61 @"iphone 5s(Global)", 62 63 @"iPod Touch 1G", 64 @"iPod Touch 2G", 65 @"iPod Touch 3G", 66 @"iPod Touch 4G", 67 @"iPod Touch 5G", 68 69 @"iPad", 70 @"iPad 2(WiFi)", 71 @"iPad 2(GSM)", 72 @"iPad 2(CDMA)", 73 @"iPad 2(WiFi + New Chip)", 74 @"iPad 3(WiFi)", 75 @"iPad 3(GSM+CDMA)", 76 @"iPad 3(GSM)", 77 @"iPad 4(WiFi)", 78 @"iPad 4(GSM)", 79 @"iPad 4(GSM+CDMA)", 80 81 @"iPad mini (WiFi)", 82 @"iPad mini (GSM)", 83 @"ipad mini (GSM+CDMA)" 84 ]; 85 NSInteger modelIndex = - 1; 86 NSString *modelNameString = nil; 87 modelIndex = [modelArray indexOfObject:deviceString]; 88 if (modelIndex >= 0 && modelIndex < [modelNameArray count]) { 89 modelNameString = [modelNameArray objectAtIndex:modelIndex]; 90 } 91 92 93 NSLog(@"----设备类型---%@",modelNameString);
注:struct utsname systemInfo; 这是LINUX系统放硬件版本的信息的地方。
附录:
1 // IOS-获取Model(设备型号)、Version(设备版本号)、app(程序版本号)等 2 NSLog(@"name: %@", [[UIDevice currentDevice] name]); 3 NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]); 4 NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]); 5 NSLog(@"model: %@", [[UIDevice currentDevice] model]); 6 NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]); 7 8 9 10 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 11 12 CFShow((__bridge CFTypeRef)(infoDictionary)); 13 14 // app名称 15 NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; 16 // app版本 17 NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 18 // app build版本 19 NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion”];
———-备注记录之用