Reputation: 11394
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
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.
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
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
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";
}
the parameter in env is private and may change but the env will likely always be a good place to check this.
Upvotes: 9