George Taskos George Taskos - 1 year ago 179
iOS Question

How can I get the iOS device CPU architecture in runtime

Is there a way to identify the iOS device CPU architecture in runtime?

Thank you.

Answer Source

You can use 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"];
                    case CPU_SUBTYPE_ARM_V7:
                    [cpu appendString:@"V7"];
                    // ...
    return [cpu autorelease];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download