三种经常使用的办法获取iOS设备的型号:html
1. [UIDevice currentDevice].model (推荐);函数
2. uname(struct utsname *name) ,使用此函数须要#include ;htm
3.sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) ,使用此函数须要#include ,#include; 推荐使用第一种方法,为最上层的API,在项目开发中推荐使用高级的API ,由于其识别度高,更简洁易用。二、3两种都是BSD级别的API ,为底层的API,不推荐。blog
示例: 1. NSString * strModel = [UIDevice currentDevice].model ;开发
2. struct utsname systemInfo get
uname(&systemInfo) string
NSString * strModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];it
3. size_t size coding
sysctlbyname ("hw.machine" , NULL , &size ,NULL ,0) model
char *model = (char *)malloc(size)
sysctlbyname ("hw.machine" , model , &size ,NULL ,0)
NSString * strModel = [NSString stringWithCString: model encoding:NSUTF8StringEncoding]; 获取了设备型号以后,还不能准确的了解其设备类型,还须要找到与其型号对应的设备说明。 如iPad2,1对应的是 iPad2(WIFI)。 此对应表已有前人很好总结出来: http://www.cnblogs.com/shadox/archive/2013/02/05/2893017.html