码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 获取最新设备型号方法

时间:2015-03-11 10:57:54      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:ios   开发   设置   模式   效果   

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 的设备号,根据对照表可以获取到当前手机型号。
完整函数:

struct utsname systemInfo;  
    uname(&systemInfo);  
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];  

    NSArray *modelArray = @[  

                            @"i386", @"x86_64",  

                            @"iPhone1,1",  
                            @"iPhone1,2",  
                            @"iPhone2,1",  
                            @"iPhone3,1",  
                            @"iPhone3,2",  
                            @"iPhone3,3",  
                            @"iPhone4,1",  
                            @"iPhone5,1",  
                            @"iPhone5,2",  
                            @"iPhone5,3",  
                            @"iPhone5,4",  
                            @"iPhone6,1",  
                            @"iPhone6,2",  

                            @"iPod1,1",  
                            @"iPod2,1",  
                            @"iPod3,1",  
                            @"iPod4,1",  
                            @"iPod5,1",  

                            @"iPad1,1",  
                            @"iPad2,1",  
                            @"iPad2,2",  
                            @"iPad2,3",  
                            @"iPad2,4",  
                            @"iPad3,1",  
                            @"iPad3,2",  
                            @"iPad3,3",  
                            @"iPad3,4",  
                            @"iPad3,5",  
                            @"iPad3,6",  

                            @"iPad2,5",  
                            @"iPad2,6",  
                            @"iPad2,7",  
                            ];  
    NSArray *modelNameArray = @[  

                                @"iPhone Simulator", @"iPhone Simulator",  

                                @"iPhone 2G",  
                                @"iPhone 3G",  
                                @"iPhone 3GS",  
                                @"iPhone 4(GSM)",  
                                @"iPhone 4(GSM Rev A)",  
                                @"iPhone 4(CDMA)",  
                                @"iPhone 4S",  
                                @"iPhone 5(GSM)",  
                                @"iPhone 5(GSM+CDMA)",  
                                @"iPhone 5c(GSM)",  
                                @"iPhone 5c(Global)",  
                                @"iphone 5s(GSM)",  
                                @"iphone 5s(Global)",  

                                @"iPod Touch 1G",  
                                @"iPod Touch 2G",  
                                @"iPod Touch 3G",  
                                @"iPod Touch 4G",  
                                @"iPod Touch 5G",  

                                @"iPad",  
                                @"iPad 2(WiFi)",  
                                @"iPad 2(GSM)",  
                                @"iPad 2(CDMA)",  
                                @"iPad 2(WiFi + New Chip)",  
                                @"iPad 3(WiFi)",  
                                @"iPad 3(GSM+CDMA)",  
                                @"iPad 3(GSM)",  
                                @"iPad 4(WiFi)",  
                                @"iPad 4(GSM)",  
                                @"iPad 4(GSM+CDMA)",  

                                @"iPad mini (WiFi)",  
                                @"iPad mini (GSM)",  
                                @"ipad mini (GSM+CDMA)"  
                                ];  
    NSInteger modelIndex = - 1;  
    NSString *modelNameString = nil;  
    modelIndex = [modelArray indexOfObject:deviceString];  
    if (modelIndex >= 0 && modelIndex < [modelNameArray count]) {  
        modelNameString = [modelNameArray objectAtIndex:modelIndex];  
    }  


    NSLog(@"----设备类型---%@",modelNameString); 

注:struct utsname systemInfo; 这是LINUX系统放硬件版本的信息的地方

附录:

?//    IOS-获取Model(设备型号)、Version(设备版本号)、app(程序版本号)等  
    NSLog(@"name: %@", [[UIDevice currentDevice] name]);  
    NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);  
    NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);  
    NSLog(@"model: %@", [[UIDevice currentDevice] model]);  
    NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);  



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

    CFShow((__bridge CFTypeRef)(infoDictionary));  

    // app名称  
    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];  
    // app版本  
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];  
    // app build版本  
    NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion”];  

iOS 获取最新设备型号方法

标签:ios   开发   设置   模式   效果   

原文地址:http://blog.csdn.net/jichunw/article/details/44177983

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