How to check if the app is running on iOS device or simulator in Delphi XE6

时光毁灭记忆、已成空白 提交于 2020-01-02 02:41:05

问题


Based on this link Conditional compilation (Delphi) CPUARM conditional if should be false for Simulator and true for device, the problem is it's not working for me. I am using Delphi XE6, iOS Simulator 7.1

This is my code

    {$IFDEF CPUARM}
s := 'iOS device';
    {$ELSE}
s := 'iOS Simulator';
    {$ENDIF}

p.s iOS Simulator is running in a VMWare virtual machine.


回答1:


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



回答2:


I found a workaround for this problem:

I defined a ISSIM condition for ALL Configuration - IOS Simulator Platform in Project->Options page , then I checked that via this

    {$IFDEF ISSIM}
s := 'iOS Simulator';
    {$ELSE}
s := 'iOS device';
    {$ENDIF}



来源:https://stackoverflow.com/questions/23803023/how-to-check-if-the-app-is-running-on-ios-device-or-simulator-in-delphi-xe6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!