码迷,mamicode.com
首页 > 其他好文 > 详细

iphone 获取硬件型号

时间:2015-02-02 23:17:38      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:ios   iphone   硬件版本   

这个写原创不知道会不会被人打,要想获取手机硬件的型号

+ (NSString *)platform
{
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    return platform;
}

+ (NSString *) getPlatform
{
    NSString *platform = [self platform];
    if ([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 (GSM)";
    if ([platform isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA/Verizon/Sprint)";
    if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4s";
    if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 GSM";
    if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 CDMA";
    if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c";
    if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s";
    if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";

    if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    
    if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (Wi-Fi Only)";
    if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (Wi-Fi/GSM/GPS)";
    if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (Wi-Fi/CDMA/GPS)";
    if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2 (Wi-Fi Only, iPad2,4)";
    if ([platform isEqualToString:@"iPad2,5"])      return @"iPad mini (Wi-Fi Only)";
    if ([platform isEqualToString:@"iPad2,6"])      return @"iPad mini (Wi-Fi/AT&T/GPS)";
    if ([platform isEqualToString:@"iPad2,7"])      return @"iPad mini (Wi-Fi/Verizon & Sprint/GPS)";

    if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3rd Gen (Wi-Fi Only)";
    if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3rd Gen (Wi-Fi/Cellular Verizon/GPS)";
    if ([platform isEqualToString:@"iPad3,3"])      return @"iPad 3rd Gen (Wi-Fi/Cellular AT&T/GPS)";
    if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4th Gen (Wi-Fi Only)";
    
    if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3rd Gen (Wi-Fi Only)";
    
    if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"])         return @"iPhone Simulator";
    
    return platform;
}
用这个就OK了,当然你要是要完整一点的对应

Apple Device                              | Model Identifier 
--------------------------------------------------------------
iPad Wi-Fi (Original)                     | iPad1,1
iPad Wi-Fi/3G/GPS (Original)              | iPad1,1
iPad 2 (Wi-Fi Only)                       | iPad2,1 
iPad 2 (Wi-Fi/GSM/GPS)                    | iPad2,2
iPad 2 (Wi-Fi/CDMA/GPS)                   | iPad2,3 
iPad 2 (Wi-Fi Only, iPad2,4)              | iPad2,4
iPad 3rd Gen (Wi-Fi Only)                 | iPad3,1 
iPad 3rd Gen (Wi-Fi/Cellular AT&T/GPS)    | iPad3,3
iPad 3rd Gen (Wi-Fi/Cellular Verizon/GPS) | iPad3,2 
iPad 4th Gen (Wi-Fi Only)                 | iPad3,4 
iPad 4th Gen (Wi-Fi/AT&T/GPS)             | Pending 
iPad 4th Gen (Wi-Fi/Verizon & Sprint/GPS) | Pending
iPad mini (Wi-Fi Only)                    | iPad2,5 
iPad mini (Wi-Fi/AT&T/GPS)                | iPad2,6
iPad mini (Wi-Fi/Verizon & Sprint/GPS)    | iPad2,7
iPhone (Original/EDGE)                    | iPhone1,1
iPhone 3G iPhone1,2 1 iPhone 3GS          | iPhone2,1
iPhone 3G (China/No Wi-Fi)                | iPhone1,2* 
iPhone 3GS (China/No Wi-Fi)               | iPhone2,1*
iPhone 4 (GSM)                            | iPhone3,1
iPhone 4 (CDMA/Verizon/Sprint)            | iPhone3,3 
iPhone 4S                                 | iPhone4,1
iPhone 5 (GSM/LTE 4, 17/North America)    | iPhone5,1 
iPhone 5 (CDMA/LTE, Sprint/Verizon/KDDI)  | iPhone5,2
iPhone 5 (GSM/LTE 1, 3, 5/International)  | iPhone5,1
iPhone 5S                                 | iPhone6,1
iPod (Original/Scroll Wheel)              | None
iPod 2nd Gen (Touch Wheel)                | None
iPod 3rd Gen (10/15/30)                   | None 
iPod 3rd Gen (10/20/40)                   | None
iPod 3rd Gen (15/20/40)                   | None
iPod 4th Gen (ClickWheel)                 | None 
iPod U2 Edition (4th Gen)                 | None 
iPod photo (30)                           | None
iPod photo (40/60)                        | None
iPod Color Display                        | None 
iPod U2 Edition (Color)                   | None
iPod 5th Gen (with Video)                 | None
iPod U2 Edition 5th Gen                   | None 
iPod 5th Gen - Enhanced                   | None 
iPod U2 Edition 5th Gen Enhanced          | None
iPod classic ("Original"/6th Gen)         | None 
iPod classic (Late 2008/7th Gen)          | None 
iPod mini                                 | None
iPod mini (2nd Gen)                       | None
iPod nano                                 | None 
iPod nano (2nd Gen)                       | None
iPod nano 2nd Gen (RED)                   | None 
iPod nano (3rd Gen/Fat)                   | None
iPod nano (4th Gen)                       | None
iPod nano (5th Gen/Camera)                | None 
iPod nano (6th Gen/1.54" Multitouch/Clip) | None
iPod nano (7th Gen/2.5" Multitouch)       | None
iPod shuffle (White)                      | None 
iPod shuffle 2nd Gen (Silver)             | None
iPod shuffle 2nd Gen (Colors/Early 2007)  | None 
iPod shuffle 2nd Gen (Late 2007)          | None
iPod shuffle 2nd Gen (Late 2008)          | None
iPod shuffle 3rd Gen                      | None
iPod shuffle 3rd Gen (Colors)             | None 
iPod shuffle 4th Gen (Wheel/VoiceOver)    | None
iPod shuffle 4th Gen (2012)               | None
iPod touch (Original)                     | iPod1,1
iPod touch (2nd Gen)                      | iPod2,1
iPod touch (3rd Gen/8 GB)                 | iPod3,1 
iPod touch (3rd Gen/32 & 64 GB)           | iPod3,1 
iPod touch (4th Gen/FaceTime)             | iPod4,1 
iPod touch (4th Gen, 2011)                | iPod4,1
iPod touch (4th Gen, 2012)                | iPod4,1
iPod touch (5th Gen)                      | iPod5,1 

iphone 获取硬件型号

标签:ios   iphone   硬件版本   

原文地址:http://blog.csdn.net/dauihiy/article/details/43412969

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!