经测试能够使用,为防止以后有这种需求,在这里记录。
在模拟器上测试打印信息是CPU_TYPE_X86
在5s上测试打印信息是CPU_TYPE_ARM64
另外,记得添加头文件 #include <mach/mach_host.h>
- (void)getCPUType{
host_basic_info_data_t hostInfo;
mach_msg_type_number_t infoCount;
infoCount = HOST_BASIC_INFO_COUNT;
host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
switch (hostInfo.cpu_type) {
case CPU_TYPE_ARM:
NSLog(@"CPU_TYPE_ARM");
break;
case CPU_TYPE_ARM64:
NSLog(@"CPU_TYPE_ARM64");
break;
case CPU_TYPE_X86:
NSLog(@"CPU_TYPE_X86");
break;
case CPU_TYPE_X86_64:
NSLog(@"CPU_TYPE_X86_64");
break;
default:
break;
}
}
参考资料:http://blog.csdn.net/shengyumojian/article/details/24643503