2013-12-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”];  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值