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.

7
  • What about different targets? Commented Sep 15, 2012 at 0: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. Commented Sep 15, 2012 at 1: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. Commented Sep 15, 2012 at 5: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.) Commented Dec 7, 2012 at 21:37
  • I have a real answer to this now. It is (obviously) not the same answer as the not-duplicate question. Commented Dec 18, 2012 at 17:23

3 Answers 3

10

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

Sign up to request clarification or add additional context in comments.

3 Comments

Clever! FYI, I am 90% sure this would occur during App Store review also. Which gives me some shifty ideas ;)
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.
For detecting TestFlight on macOS refer to this gist.
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.

3 Comments

I guess it won't work since TestFlight accepts productions builds in Apple section
Official store releases shouldn't include a embedded.mobileprovision. The new iTunes Connect TestFlight builds may or may not; you should probably just check.
I confirm that this technique is not working anymore since iOS 9.1 + TestFlight with production build.
-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.

1 Comment

The question specifically asks how to do it using the same build configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.