Determine if iOS device is 32- or 64-bit

前端 未结 7 580
清歌不尽
清歌不尽 2020-12-01 04:03

Does anyone know of an easy way to tell if an iOS7 device has 32- or 64-bit hardware? I don\'t mean programmatically, I just mean via settings, model number, 3rd-party app,

7条回答
  •  情书的邮戳
    2020-12-01 04:27

    Totally untested, but you should be able to get the CPU via sysctl like this:

    #include 
    #include 
    #include 
    
    void foo() {
        size_t size;
        cpu_type_t type;
    
        size = sizeof(type);
        sysctlbyname("hw.cputype", &type, &size, NULL, 0);
    
        if (type == CPU_TYPE_ARM64) {
            // ARM 64-bit CPU
        } else if (type == CPU_TYPE_ARM) {
            // ARM 32-bit CPU
        } else {
            // Something else.
        }
    }
    

    In the iOS 7 SDK, CPU_TYPE_ARM64 is defined in as:

    #define CPU_TYPE_ARM64          (CPU_TYPE_ARM | CPU_ARCH_ABI64)
    

    A different way seems to be:

    #include 
    
    void foo() {
        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);
    
        if (hostInfo.cpu_type == CPU_TYPE_ARM64) {
            // ARM 64-bit CPU
        } else if (hostInfo.cpu_type == CPU_TYPE_ARM) {
            // ARM 32-bit CPU
        } else {
            // Something else.
        }
    }
    

提交回复
热议问题