iOS,判断iPhone芯片是32位还是64位

转  https://blog.csdn.net/k178441367/article/details/45842627

从后台获取的userid  用long类型接收的 ,在 iPhone5 和5以上的手机上面表现不同, 于是网上搜了下

从老外网上搜到的几种判断ios 32,64位的办法

方法一:

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

    }

}

方法二:

#if defined(__arm__)

    NSLog(@"32-bit App");

#elif defined(__arm64__)

    NSLog(@"64-bit App");

#else

    NSLog(@"Not running ARM");

#endif

方法三:

if (sizeof(void*) == 4) {

    NSLog(@"32-bit App");

} else if (sizeof(void*) == 8) {

    NSLog(@"64-bit App");

}

方法四:

#include

+ (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;

}

---------------------

作者:wnphp

来源:CSDN

原文:https://blog.csdn.net/k178441367/article/details/45842627

版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(iOS,判断iPhone芯片是32位还是64位)