6

I need to implement a custom logging in my app.

To do this i need to detect if the current version of the app has been installed from the app store or is running from xcode or is a TestFlight version.

There is something different in the app depending from the installation source?

I don't want to have something different in the development environment.

bago
  • 108
  • 1
  • 9

2 Answers2

11

You can get part of the way there by reading in the embedded.mobileprovision file from the application bundle:

NSString *provisionPath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];

If that does not exist, you are in an app store build.

If it does exist, you need to figure out some difference between your debug and ad-hoc provisioning profiles, and look for that to determine which build you are in.

Because XCode automatically sets up applications with a "DEBUG" flag in the Debug config, that is not set in Release (which is used by default for AdHoc builds), you may be better off disabling logging in an app store build and determining the level of logging based on the DEBUG macro flag.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • 1
    That looks great, do you think i can find a way to test it before i release the app? for example build and run with the _Release Scheme_ just to be sure it works on release. – bago Apr 18 '13 at 17:55
  • All applications you compile, release or ad-hoc, will always include an embedded.mobileprovision. It's only the final App Store build that is missing this file. You can verify it does not exist by downloading any app store app from your device, and exploring the application bundle... Note that I didn't come up with this technique, HockeyApp gets full credit for finding this (or at least that's where I learned about it from). – Kendall Helmstetter Gelner Apr 18 '13 at 18:12
  • Take a look at this SO answer for code on detecting debug vs ad-hoc: http://stackoverflow.com/a/17930198/1216830 – CharlesA Nov 06 '13 at 10:17
  • 1
    This doesn't work anymore with the official TestFlight beta process from Apple since they typically go through the same Release config. Any idea what to do then? Yes, a separate build config is still possible, but it'd be great if you could use the same Release config for both and still determine if this is a beta version (with the orange circle) or the released version from the App Store. – Adrian Schönig Jan 28 '15 at 05:04
  • @bago you can test it through TestFlight for the reason well explained by Adrian – loretoparisi Jul 07 '15 at 17:15
0

You could use build configurations that define a macro to let you know that you've built for testflight.

For example, we have debug builds set a macro USE_TESTFLIGHT, and in our code we do:

#ifdef USE_TESTFLIGHT
//do something test-flight specific
[TestFlight takeOff:kTestFlightAppToken];
#endif

You could create new build configs that setup different macros depending on how you are compiling/distributing the app, and use ifdef's to perform different tasks based on those.

KaosDG
  • 466
  • 2
  • 7