在做 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 ---------- */
附:iOS 设备列表最新对照表https://www.theiphonewiki.com/wiki/Models
声明:此博文源自 http://blog.csdn.net/shenyuanluo/article/details/49176971
如需转载,请说明博文出处。谢谢!