This question gives an excellent way to determine the real device in use. But what about when running on the simulator and I want to detect if I am running on a retina or 64-bit version so I can trigger special logic?
Asked
Active
Viewed 124 times
1
-
For retina, look at the scale of the screen. For the 64-bit version, you may check this:http://stackoverflow.com/questions/19043915/code-to-check-ios-32-bit-or-64-bit – Larme Mar 15 '14 at 17:32
-
@John You should clarify whether you wish to determine if the currently running app is running in 32-bit mode or whether you want to know whether the device supports 64-bit mode or not. A 32-bit app will run in 32-bit mode on a 64-bit device. Which do you care about? – rmaddy Mar 15 '14 at 17:36
-
Good point. I specifically want to check that the app itself is running as 64-bit i.e. the hardware and app both support 64-bit. In other words, your answer _is_ addressing what I want. – Mr. Boy Mar 17 '14 at 09:52
2 Answers
2
You can determine whether a device (or simulator) is retina by looking at the value for [UIScreen mainScreen].scale
. If it's 1, it's non-retina. If it's 2, it's retina.
There are probably several ways of detecting 64/32-bit. One way would be:
if (sizeof(CGFloat) == sizeof(double)) {
// 64-bit
} else {
// 32-bit
}
Please note that this checks the app, not the device. A 32-bit app will run on a 64-bit device. The above code only returns true if the app was built to support 64-bit and the device is 64-bit.

rmaddy
- 314,917
- 42
- 532
- 579
0
You can detect whether the device/simulator is retina by inspecting the scale
of [UIScreen mainScreen]
.
To determine CPU type in runtime, you can use:
#include <mach/mach_host.h>
...
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);
switch (hostInfo.cpu_type) {
case CPU_TYPE_ARM:
break;
case CPU_TYPE_ARM64:
break;
case CPU_TYPE_X86:
break;
case CPU_TYPE_X86_64:
break;
default:
break;
}

Léo Natan
- 56,823
- 9
- 150
- 195