17

I would prefer to use the same build configuration for TestFlight vs. App Store. Is there a way to detect at runtime whether the app has been installed via TestFlight or the App Store? (My thinking is I'll only call takeOff if it's not installed via the App Store.)

I want to avoid using TestFlight in App Store builds to protect my users' privacy, and also to avoid the potential derailing of networking discussed here.

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • What about different targets? – Jessedc Sep 15 '12 at 00:55
  • I think that'd break Xcode's Archives. I think I'm asking the wrong question here. Unless someone has a better idea, I'm going to just add a TestFlight switch to my app and default it to off. – Steven Fisher Sep 15 '12 at 01:24
  • 1
    Xcode archive is fine with different targets. I often use different targets for internal releases, others for app store. They allow the same configurations (debug, release) but you can set up different build settings to compile TF out of production/app store targets. – Jessedc Sep 15 '12 at 05:01
  • That's a helpful question but not a duplicate; I'm looking for a runtime check, rather than compile time. (Also, no monotouch. But I think that'd be easily fixed by removing the monotouch tag from the other question.) – Steven Fisher Dec 07 '12 at 21:37
  • I have a real answer to this now. It is (obviously) not the same answer as the not-duplicate question. – Steven Fisher Dec 18 '12 at 17:23
  • Simpler idea: Dupe it to this one, which actually is the same question: http://stackoverflow.com/questions/9906504/check-if-ios-app-is-live-in-app-store – Steven Fisher Dec 18 '12 at 18:07
  • Check this: https://stackoverflow.com/a/27398665/419348 – AechoLiu Jun 28 '18 at 02:04

3 Answers3

9

To determine Debug, TestFlight or AppStore deployment in Swift:

  private static let isTestFlight = NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"

  // This can be used to add debug statements.
  static var isDebug: Bool {
    #if DEBUG
      return true
    #else
      return false
    #endif
  }

Complete source and sample: https://stackoverflow.com/a/33830605/639227

Community
  • 1
  • 1
LorenzoValentijn
  • 1,381
  • 1
  • 11
  • 12
  • Clever! FYI, I am 90% sure this would occur during App Store review also. Which gives me some shifty ideas ;) – Jon Willis Aug 22 '18 at 23:25
  • Unfortunately no luck with TestFlight macOS builds. I do get the content of the sandbox receipt, but it's named `receipt` like the non-sandbox one. – keeshux Nov 11 '21 at 15:19
  • For detecting TestFlight on macOS refer to [this gist](https://gist.github.com/lukaskubanek/cbfcab29c0c93e0e9e0a16ab09586996). – Lukáš Kubánek Dec 12 '21 at 14:30
7

I believe this to be close enough to a duplicate of Check if iOS app is live in app store that this can be closed.

You can determine if your app was distributed via the app store by checking for the absence of embedded.mobileprovision. This file is only included in adhoc builds. It follows that if you're distributing builds only via TestFlight or HockeyApp and it is not a store build, it must be a TestFlight or HockeyApp build.

Like this:

if ([[NSBundle mainBundle] pathForResource:@"embedded"
                                    ofType:@"mobileprovision"]) {
  // not from app store
} else {
  // from app store
}

This technique is from the HockeyApp SDK.

Community
  • 1
  • 1
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • 1
    I guess it won't work since TestFlight accepts productions builds in Apple section – zaplitny Feb 24 '15 at 07:57
  • 1
    Official store releases shouldn't include a `embedded.mobileprovision`. The new iTunes Connect TestFlight builds may or may not; you should probably just check. – Steven Fisher Feb 24 '15 at 16:16
  • 6
    I confirm that this technique is not working anymore since `iOS 9.1` + TestFlight with production build. – loretoparisi May 16 '16 at 09:47
-1

Here is a blog post that shows you how to add additional configurations besides Debug and Release (ex. Beta).

And after you add Beta configuration, you create another project scheme. And then edit this new scheme. Under section Archive please select to use Beta configuration. Then you use this scheme for archiving for Testflight and previous scheme for achiving for app store.

Klemen
  • 2,144
  • 2
  • 23
  • 31