如何在运行时可以获得iOS设备CPU架构
2019年09月11日
作者:佚名
有没有办法在运行时识别iOS设备的CPU架构?
谢谢.
解决方法
您可以使用sysctlbyname:
#include <sys/types.h> #include <sys/sysctl.h> #include <mach/machine.h> NSString *getCPUType(void) { NSMutableString *cpu = [[NSMutableString alloc] init]; size_t size; cpu_type_t type; cpu_subtype_t subtype; size = sizeof(type); sysctlbyname("hw.cputype",&type,&size,NULL,0); size = sizeof(subtype); sysctlbyname("hw.cpusubtype",&subtype,0); // values for cputype and cpusubtype defined in mach/machine.h if (type == CPU_TYPE_X86) { [cpu appendString:@"x86 "]; // check for subtype ... } else if (type == CPU_TYPE_ARM) { [cpu appendString:@"ARM"]; switch(subtype) { case CPU_SUBTYPE_ARM_V7: [cpu appendString:@"V7"]; break; // ... } } return [cpu autorelease]; }
以上是来客网为你收集整理的如何在运行时可以获得iOS设备CPU架构全部内容,希望文章能够帮你解决如何在运行时可以获得iOS设备CPU架构所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。