ios - 如何在运行时获取 iOS 设备 CPU 架构

标签 ios objective-c cpu-architecture

有没有办法在运行时识别 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, &size, NULL, 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 - 如何在运行时获取 iOS 设备 CPU 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19859388/

相关文章:

ios - 如何同时写入Realm的不同对象?

ios - 进度 View 循环

objective-c - Core Data 应用程序中的多个 View 和源列表

android - 我们什么时候需要添加对arm64-v8a的支持?

cpu-architecture - DMA 如何/如何处理多个并发传输?

caching - 什么是引用地点?

ios - AVFoundation 不允许以 240fps 捕获视频

ios - 如何使用 Alamofire 完全禁用 URLCache

objective-c - Cocoa中如何从子类委托(delegate)方法调用父类(super class)委托(delegate)方法?

ios - 无法在 Objective-C 中使用 Swift 类