views:

321

answers:

2

Question about best practices.

Is there a way to programmatically detect whether the app is being compiled for an AdHoc configuration, and, if so, enable a feature in the app?

For example, I am thinking of enabling a switch between beta and prod environment given depending on whether the app is an an AdHoc vs. Release configuration.

This way we can give testers the ability to switch between server environments in the same app.

Could do this with a #define but thought I would ask if there is a more elegant way to do it by detecting the current configuration.

+5  A: 

You can set a custom define in your configuration using the Preprocessor Macros setting in your project or target info. This works just as if you had #define'd a variable in your source.

In your release configuration, set GCC_PREPROCESSOR_DEFINITIONS ("Preprocessor Macros") to MYAPP_RELEASE=1. You can then use this code to change functionality at compile-time:

#ifdef MYAPP_RELEASE
    NSString *title = @"Release Version";
#else
    NSString *title = @"Beta Version";
#endif
pix0r
This also useful for enabling / disabling features when compiling for a Lite application target using the same project as your full version.
Brad Larson
A: 

You could also have a different plist key for the configurations and then have your app read from the .plist file at runtime like...

CFBundleRef mainBundle;
CFDictionaryRef bundleInfoDict;
mainBundle = CFBundleGetMainBundle();
bundleInfoDict = CFBundleGetInfoDictionary(mainBundle);

if (bundleInfoDict != NULL) {
  // check for your custom config key here
}
EPiddy
That works too, but generally you don't have a different Info.plist file setup for AdHoc vs. Release configurations. I don't think there are any other settings here that you'd need to change. You also might find the Cocoa interface to the bundle/plist easier to use: `NSString *myKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"myInfoPlistKeyName"];`
pix0r