20

In the past I've had separate build configurations for production and beta builds distributed through TestFlight. This made it easy to make modifications to beta builds, such as exposing additional settings the app to let testers test things more thoroughly and see more technical information about the status of the app.

Is there a way to check if an app has been distributed through Apple's TestFlight to make changes to how the app runs? Compiler directives no longer make sense as the same build can be distributed to beta testers and submitted to the store, but perhaps there's a way to check at runtime.

Anthony Mattox
  • 7,048
  • 6
  • 43
  • 59

1 Answers1

37

This works:

if ([[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]) {
    // TestFlight
} else {
    // App Store (and Apple reviewers too)
}

Update

The above method doesn't seem to work anymore, Apple changed the way they sign TestFlight builds. This does work however:

BOOL isRunningTestFlightBeta = [[[[NSBundle mainBundle] appStoreReceiptURL] lastPathComponent] isEqualToString:@"sandboxReceipt"];
Kevin Renskers
  • 5,156
  • 4
  • 47
  • 95
  • Looks reasonable enough. I'm not going to test it immediately, can you point to any confirmation of this? Effecting apple reviewers is an interesting side effect. – Anthony Mattox Dec 10 '14 at 14:21
  • I found this answer in multiple SO questions, and confirmed that the TestFlight app does indeed take that first path. HockeyApp is also using the same approach in their SDK, so I assume it's safe. – Kevin Renskers Dec 10 '14 at 14:51
  • 3
    While TestFlight does take that first path, I have just confirmed that Apple's reviewers do NOT. They take the App Store path, which is really bad news for me :( – Kevin Renskers Dec 20 '14 at 11:13
  • Looks good to me for what I need. Has anybody gotten this thru the AppStore review and then verified the desired result (that the AppStore download takes the path of the 'else' statement)? – ProgrammierTier Jun 30 '15 at 18:05
  • 3
    I'm using this in a production app, 12 updates so far, all passed review just fine. – Kevin Renskers Jun 30 '15 at 18:07
  • Is this works for any bundle? (IE. extensions or widget bundle, watch bundle) – jeeeyul Aug 24 '15 at 02:34
  • Hey, @mixedCase, that's great tip! Could you please attach a link to any docs on this? Just wanted to be sure before using in production (is it the same across different ios versions for e.g.) – Danik Sep 28 '15 at 10:37
  • I don't have a link, sorry. But we've been using this since iOS 7 all the way up to iOS 9. I know that HockeyApp is using the same approach. – Kevin Renskers Sep 28 '15 at 10:38
  • 3
    It seems that this no longer works for iOS 9 :( – Kevin Renskers Sep 30 '15 at 09:39
  • Updated my answer with a new way of detecting TestFlight builds. Got it from http://stackoverflow.com/questions/26081543/how-to-tell-at-runtime-whether-an-ios-app-is-running-through-a-testflight-beta-i?lq=1. – Kevin Renskers Sep 30 '15 at 14:14
  • No longer works for iOS 10 and Xcode8. Returns "receipt" regardless. – nickdnk Nov 26 '16 at 10:36
  • @nickdnk do you have an alternative to this on iOS 10? I've been relentlessly looking for a way to do this but every solution seems to be outdated now. – halileohalilei Dec 06 '16 at 13:26
  • Nope, sorry. I ended up just moving on. My problem was with push environment, but TestFlight uses production, so it doesn't matter to me anyway. – nickdnk Dec 07 '16 at 15:17
  • FYI: the latest update broke w/ iOS 13; better to just use a config variable in info.plist for a specific beta/testflight build – iwasrobbed Apr 01 '20 at 05:32