三种常用的办法获取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];