Determinar se o dispositivo iOS é de 32-ou 64-bits

Alguém sabe de uma maneira fácil de dizer se um dispositivo iOS7 tem hardware de 32 ou 64 bits? Eu não quero dizer programaticamente, eu só quero dizer através de Configurações, número de modelo, aplicação de terceiros, etc.

Estou a ter um problema que suspeito estar relacionado com 64 bits. O Conselho da Apple é testar no simulador de 64 bits, mas também num dispositivo de 64 bits, mas não diz nada sobre como determinar isso. Eu posso escrever um aplicativo de teste para verificar o tamanho (int) ou o que quer que, mas tem que haver alguma maneira de, suporte técnico para saber com o que estão a trabalhar.

Eric

 29
ios
Author: Eric McNeill, 2013-11-20

7 answers

Não há outra forma "oficial" de O determinar. Você pode determiná - lo usando este código:
if (sizeof(void*) == 4) {
    NSLog(@"32-bit App");
} else if (sizeof(void*) == 8) {
    NSLog(@"64-bit App");
}
 34
Author: Nikos M., 2014-01-11 09:09:33

Abaixo está o método is64bitHardware. Ele retorna Sim se o hardware é um hardware de 64 bits e funciona em um dispositivo iOS real e em um simulador iOS. Aqui está Fonte .

#include <mach/mach.h>

+ (BOOL) is64bitHardware
{
#if __LP64__
    // The app has been compiled for 64-bit intel and runs as 64-bit intel
    return YES;
#endif

    // Use some static variables to avoid performing the tasks several times.
    static BOOL sHardwareChecked = NO;
    static BOOL sIs64bitHardware = NO;

    if(!sHardwareChecked)
    {
        sHardwareChecked = YES;

#if TARGET_IPHONE_SIMULATOR
        // The app was compiled as 32-bit for the iOS Simulator.
        // We check if the Simulator is a 32-bit or 64-bit simulator using the function is64bitSimulator()
        // See http://blog.timac.org/?p=886
        sIs64bitHardware = is64bitSimulator();
#else
        // The app runs on a real iOS device: ask the kernel for the host info.
        struct host_basic_info host_basic_info;
        unsigned int count;
        kern_return_t returnValue = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count);
        if(returnValue != KERN_SUCCESS)
        {
            sIs64bitHardware = NO;
        }

        sIs64bitHardware = (host_basic_info.cpu_type == CPU_TYPE_ARM64);

#endif // TARGET_IPHONE_SIMULATOR
    }

    return sIs64bitHardware;
}
 10
Author: Dragos, 2014-05-30 19:01:14

Totalmente não testado, mas você deve ser capaz de obter a CPU via sysctl Assim:

#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>

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.
    }
}

No iOS 7 SDK, CPU_TYPE_ARM64 está definido em <mach/machine.h> como:

#define CPU_TYPE_ARM64          (CPU_TYPE_ARM | CPU_ARCH_ABI64)

Uma maneira diferente parece ser:

#include <mach/mach_host.h>

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.
    }
}
 7
Author: DarkDust, 2013-11-20 19:33:15

Se estiver a compilar com clang, existe outra forma: verifique se __arm__ ou __arm64__ está definido.

O código de exemplo abaixo não é testado, mas deve ilustrar o que quero dizer com isso:

#if defined(__arm__)
    NSLog(@"32-bit App");
#elif defined(__arm64__)
    NSLog(@"64-bit App");
#else
    NSLog(@"Not running ARM");
#endif

Note que isto se baseia no facto de os binários de aplicação iOS actuais conterem ambos, 32 bits e 64 bits num único contentor e eles serão seleccionados correctamente, dependendo se a sua aplicação suporta a execução de 64 bits.

 6
Author: gns-ank, 2015-05-13 11:43:26

Pode utilizar bitWidth em Int https://developer.apple.com/documentation/swift/int/2885648-bitwidth

static var is32Bit: Bool {
    return Int.bitWidth == 32
}

static var is64Bit: Bool {
    return Int.bitWidth == 64
}
 3
Author: jherg, 2017-12-11 21:23:19

Uso isto no swift 4, não sei se é a melhor solução, mas funciona.

   func getCPUArch()
   {
      #if arch(arm)
         print("this is a 32bit system")
      #elseif arch(arm64)
          print("this is a 64bit system")
      #endif
   }
 3
Author: Sam Trent, 2017-12-29 04:47:37

Em tempo de execução pode usar algo como isto

extension UIDevice {
    static let is64Bit = MemoryLayout<Int>.size == MemoryLayout<Int64>.size
}
 1
Author: Andrei Pachtarou, 2017-12-04 15:39:53