utilizan usa tendran que para equipos dispositivos ios

usa - Determine si el dispositivo iOS es de 32 o 64 bits



iphone se ios (7)

A continuación se muestra el método is64bitHardware. Devuelve SÍ si el hardware es un hardware de 64 bits y funciona en un dispositivo iOS real y en un simulador de iOS. Aquí está la source .

#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; }

¿Alguien sabe de una manera fácil de saber si un dispositivo iOS7 tiene hardware de 32 o 64 bits? No quiero decir programáticamente, solo me refiero a través de la configuración, el número de modelo, la aplicación de terceros, etc.

Tengo un problema que sospecho está relacionado con 64 bits. El consejo de Apple es probar en el simulador de 64 bits, pero también en un dispositivo real de 64 bits, pero luego no dice nada sobre cómo determinar eso. Puedo escribir una aplicación de prueba para verificar sizeof (int) o lo que sea, pero tiene que haber alguna manera, por ejemplo, de soporte técnico para saber con qué están trabajando.

Eric


En tiempo de ejecución puedes usar algo como esto.

extension UIDevice { static let is64Bit = MemoryLayout<Int>.size == MemoryLayout<Int64>.size }


No hay otra forma "oficial" de determinarlo. Puedes determinarlo usando este código:

if (sizeof(void*) == 4) { NSLog(@"32-bit App"); } else if (sizeof(void*) == 8) { NSLog(@"64-bit App"); }



Si está compilando con clang, hay otra forma: simplemente verifique si __arm__ o __arm64__ está definido.

El código de ejemplo a continuación no se ha probado, pero debería ilustrar lo que quiero decir con eso:

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

Tenga en cuenta que esto se basa en el hecho de que los binarios actuales de la aplicación iOS contienen ambos binarios de 32 bits y 64 bits en un solo contenedor y se seleccionarán correctamente dependiendo de si su aplicación admite la ejecución de 64 bits.


Totalmente sin probar, pero debería poder obtener la CPU a través de sysctl esta manera:

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

En el SDK de iOS 7, CPU_TYPE_ARM64 se define en <mach/machine.h> como:

#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)

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


Uso esto en swift 4, no estoy seguro de si es la mejor solución pero funciona.

func getCPUArch() { #if arch(arm) print("this is a 32bit system") #elseif arch(arm64) print("this is a 64bit system") #endif }