iOS之设备型号获取

在做 iOS 开发时,不可避免的遇到需要适配各个型号的分辨率问题,此时很有必要准确的获取设备的具体型号以设计对应的显示效果。

方法如下:

#import <sys/utsname.h>


/*
 * ===  FUNCTION  ==================================================
 *         Name:  getDeviceInfo
 *  Description:  Get the iPhone device information
 * =================================================================
 */
-(void)getDeviceInfo
{
    struct utsname systemInfo;//<span style="color: rgb(51, 51, 51); font-family: Menlo; line-height: 26px;">这是Linux系统放硬件版本的信息的地方</span>
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    NSLog(@"systemInfo.machine:%@",deviceString);
    if ( [deviceString rangeOfString:@"iPhone1,2"].length > 0)   // iPhone 3G
    {
        NSLog(@"It's iPhone 3G device !");
    }
    else if ( [deviceString rangeOfString:@"iPhone2"].length > 0)   // iPhone 3GS
    {
        NSLog(@"It's iPhone 3GS device !");
    }
    else if ( [deviceString rangeOfString:@"iPhone3"].length > 0)   // iPhone 4
    {
        NSLog(@"It's iPhone 4 device !");
    }
    else if ( [deviceString rangeOfString:@"iPhone4"].length > 0)   // iPhone 4s
    {
        NSLog(@"It's iPhone 4s device !");
    }
    else if ( [deviceString rangeOfString:@"iPhone5"].length > 0)   // iPhone 5、iPhone 5c
    {
        NSLog(@"It's iPhone 5 and iPhone 5c device !");
    }
    else if( [deviceString rangeOfString:@"iPhone6"].length > 0 )  // iPhone 5s
    {
        NSLog(@"It's iPhone 5s device !");
    }
    else if( [deviceString rangeOfString:@"iPhone7"].length > 0 )  // iPhone 6、iPhone 6 Plus
    {
        NSLog(@"It's iPhone 6 and iPhone 6 Plus device !");
    }
    else if ( [deviceString rangeOfString:@"iPhone8"].length > 0)   // iPhone 6s、iPhone 6s Plus
    {
        NSLog(@"It's iPhone 6s and iPhone 6s Plus device !");
    }
}       /* ----------  end of function getDeviceInfo  ---------- */


其他比如:Apple Watch,Apple TV,iPad,iPad mini,iPod touch等设备信息获取,类似的!

iOS 设备列表最新对照表https://www.theiphonewiki.com/wiki/Models


声明:此博文源自 http://blog.csdn.net/shenyuanluo/article/details/49176971

如需转载,请说明博文出处。谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值