dev4life
dev4life

Reputation: 11394

how to detect if app was launched from xcode?

how to detect if my app was launched from xcode after compilation or from package bundle downloaded from itunes?

The code below does not seem to work, given that the else block always gets executed when I build and run it from xcode.

#if (TARGET_OS_SIMULATOR)

#else
    //Xcode did not launch this app
#endif

Upvotes: 5

Views: 1388

Answers (2)

Rhm Akbari
Rhm Akbari

Reputation: 360

This is what I think is the best solution I used it in many apps. First set a DEBUG variable in your project's 'Build Setting' in the section shown in the picture. enter image description here

Then use it in your code this way. The code in the #ifdef branch does not even get compiled when the app is being built for release or distribution.

#ifdef DEBUG
    // in debug mode when running off of XCode in debug mode
#else
    // running off of XCode in release mode or downloaded from App Store
#endif

Upvotes: 2

Daij-Djan
Daij-Djan

Reputation: 50089

I dont see a WIDE use for this but it is possible by looking at the environment variables. namely is OS_ACTIVITY_DT_MODE" = YES when started via xcode

EXAMPLE:

NSDictionary *environment = [[NSProcessInfo processInfo] environment];
UITextView *v = self.view.subviews.firstObject;

if([environment[@"OS_ACTIVITY_DT_MODE"] boolValue]) {
    v.text = @"xcode attached";
}
else {
    v.text = @"not xcode";
}

NOTE:

the parameter in env is private and may change but the env will likely always be a good place to check this.

Upvotes: 9

Related Questions