有没有办法在运行时识别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]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。