0

There is the #if targetEnvironment(simulator) compiler directive and it would be useful if there was a way to tell whether the app running on a device was launched from Xcode and is connected to the debugger.

Is there a way to detect this in the app?

Using debug/release builds and DEBUG variable would be less suited in our situation.

exp
  • 410
  • 6
  • 11
  • [#ifdef replacement in the Swift language](https://stackoverflow.com/questions/24003291/ifdef-replacement-in-the-swift-language) this may help you – Dinesh Nagarajan Jul 16 '19 at 15:48

1 Answers1

0

Yes, you could put launch arguments in your scheme (edit scheme -> run -> arguments) that will only be applied when launching from xcode, if launching from tapping on the app icon or downloaded from app store, these launch arguments will not be present so you will be able to tell if the app is launched from Xcode or not.

You can get a launch argument by going

if NSProcessInfo.processInfo().environment["ARGUMENT_NAME"] != nil {
    // launched from Xcode
}
Fonix
  • 11,447
  • 3
  • 45
  • 74