Checking for CPUARM
is the correct solution. iOS binaries compiled for the simulator are not ARM, they are actually x86. Just make sure to wrap your iOS code with {$IFDEF IOS}
:
{$IFDEF IOS}
{$IFDEF CPUARM}
s := 'iOS device';
{$ELSE}
s := 'iOS Simulator';
{$ENDIF}
{$ENDIF}
Delphi uses an ARM compiler for iOS devices, but uses an x86 compiler for the iOS simulator.
The available compiler conditionals are documented on Embarcadero's DocWiki:
Conditional compilation (Delphi) | Predefined Conditionals
CPUARM
is defined by the DCCIOSARM compiler (iOS device).
CPU386
and CPUX86
are defined by the DCCIOS32 compiler (iOS simulator).
A look at the conditional values that are physically present in XE6's DCCIOSARM.EXE and DCCIOS32.EXE executable files confirms that:
DCCIOSARM.EXE:
**CPUARM**
DCC
NEXTGEN
AUTOREFCOUNT
WEAKINSTREF
WEAKINTFREF
WEAKREF
EXTERNALLINKER
NATIVECODE
POSIX
POSIX32
MACOS
MACOS32
**IOS**
VER270
CONSOLE
BCB
PIC
UNICODE
CONDITIONALEXPRESSIONS
DCCIOS32.EXE:
**CPU386**
**CPUX86**
DCC
NEXTGEN
AUTOREFCOUNT
WEAKINSTREF
WEAKINTFREF
WEAKREF
NATIVECODE
POSIX
POSIX32
MACOS
MACOS32
**IOS**
ALIGN_STACK
UNDERSCOREIMPORTNAME
PC_MAPPED_EXCEPTIONS
ASSEMBLER
VER270
CONSOLE
BCB
PIC
UNICODE
CONDITIONALEXPRESSIONS
UPDATE: starting with Delphi 11.2, the ARM-based iOS simulator is now supported via the new DCCIOSSIMARM64 compiler. You can use the IOSSIMULATOR
conditional to check for that compiler:
{$IFDEF IOS}
{$IFDEF CPUARM}
{$IFDEF IOSSIMULATOR}
s := 'iOS Simulator (ARM)';
{$ELSE}
s := 'iOS device';
{$ENDIF}
{$ELSE}
s := 'iOS Simulator (x86)';
{$ENDIF}
{$ENDIF}
delphi
tag to your Delphi related questions. Maybe you were wondering for the low attention on your questions. That is the reason :o) – Rosati