IOS 獲取最新設備型號方法

1.IOS 獲取最新設備型號方法
列表最新對照表:http://theiphonewiki.com/wiki/Models
方法:

#import "sys/utsname.h”

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. struct utsname systemInfo;  
  2.    uname(&systemInfo);  
  3.   
  4.    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];  

這樣得到的   deviceString  是iPhone5,2 的設備號,根據對照表可以獲取到當前手機型號。

完整函數:

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  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系統放硬件版本的信息的地方

附錄:

//手機序列號  

 NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier]; 

NSLog(@"手機序列號: %@",identifierNumber); 

 //手機別名: 用戶定義的名稱  

 NSString* userPhoneName = [[UIDevice currentDevice] name]; 

NSLog(@"手機別名: %@", userPhoneName); 

//設備名稱  

NSString* deviceName = [[UIDevice currentDevice] systemName]; 

NSLog(@"設備名稱: %@",deviceName ); 

//手機系統版本  

NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 

NSLog(@"手機系統版本: %@", phoneVersion); 

//手機型號  

NSString* phoneModel = [[UIDevice currentDevice] model]; 

NSLog(@"手機型號: %@",phoneModel ); 

//地方型號  (國際化區域名稱)  

NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel]; 

NSLog(@"國際化區域名稱: %@",localPhoneModel );

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 

// 當前應用名稱  

NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; 

NSLog(@"當前應用名稱:%@",appCurName); 

// 當前應用軟件版本  比如:1.0.1  

NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 

NSLog(@"當前應用軟件版本:%@",appCurVersion); 

// 當前應用版本號碼   int類型  

NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"]; 

NSLog(@"當前應用版本號碼:%@",appCurVersionNum); 

2012-10-19 14:07:47.622 myDemo[5779:707] 手機序列號: 6685c75e34104be0b04c6ceb72985dc381f0f746

2012-10-19 14:07:47.624 myDemo[5779:707] 手機別名: “spring sky”的 iPod

2012-10-19 14:07:47.627 myDemo[5779:707] 設備名稱: iPhone OS

2012-10-19 14:07:47.629 myDemo[5779:707] 手機系統版本: 5.1.1

2012-10-19 14:07:47.641 myDemo[5779:707] 手機型號: iPod touch

2012-10-19 14:07:47.642 myDemo[5779:707] 國際化區域名稱: iPod touch

2012-10-19 14:07:47.643 myDemo[5779:707] 當前應用名稱:myDemo

2012-10-19 14:07:47.645 myDemo[5779:707] 當前應用軟件版本:1.0.1

2012-10-19 14:07:47.646 myDemo[5779:707] 當前應用版本號碼:101

[objc] view plaincopy在CODE上查看代碼片派生到我的代碼片
  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”];  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章