三种常用的办法获取iOS设备的型号:
1. [UIDevice currentDevice].model (推荐);
2. uname(struct utsname *name) ,使用此函数需要#include ;
3.sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) ,使用此函数需要#include ,#include; 推荐使用第一种方法,为最上层的API,在项目开发中推荐使用高级的API ,因为其识别度高,更简洁易用。2、3两种都是BSD级别的API ,为底层的API,不推荐。
示例: 1. NSString * strModel = [UIDevice currentDevice].model ;
2. struct utsname systemInfo
uname(&systemInfo)
NSString * strModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
3. size_t size
sysctlbyname ("hw.machine" , NULL , &size ,NULL ,0)
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