How to tell at runtime whether an iOS application is running with a test installation of TestFlight

Is it possible to detect at runtime that the application was installed through the beta version of TestFlight (sent via iTunes Connect) and in the App Store? You can send one set of applications and receive it through both. Is there an API that can determine how it was installed? Or does the receipt contain information that allows this to be determined?

+64
ios testflight
Sep 28 '14 at 4:12
source share
5 answers

For an application installed through TestFlight beta, the receipt file is called StoreKit\sandboxReceipt compared to the regular StoreKit\receipt . Using [NSBundle appStoreReceiptURL] , you can search for sandboxReceipt at the end of the URL.

 NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSString *receiptURLString = [receiptURL path]; BOOL isRunningTestFlightBeta = ([receiptURLString rangeOfString:@"sandboxReceipt"].location != NSNotFound); 

Note that sandboxReceipt also the name of the receipt file when the assembly starts locally and is executed in the simulator for the assembly.

+73
Sep 30 '14 at 5:47
source share

Based on the combinatorial answer, I created the following helper class SWIFT. With this class, you can determine if there is debugging, testflight, or an appstore assembly.

 enum AppConfiguration { case Debug case TestFlight case AppStore } struct Config { // This is private because the use of 'appConfiguration' is preferred. 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 } static var appConfiguration: AppConfiguration { if isDebug { return .Debug } else if isTestFlight { return .TestFlight } else { return .AppStore } } } 

We use these methods in our project to provide different id tracking lines or for each environment:

  func getURL(path: String) -> String { switch (Config.appConfiguration) { case .Debug: return host + "://" + debugBaseUrl + path default: return host + "://" + baseUrl + path } } 

OR

  static var trackingKey: String { switch (Config.appConfiguration) { case .Debug: return debugKey case .TestFlight: return testflightKey default: return appstoreKey } } 

UPDATE 05-02-2016: A prerequisite for using a preprocessor macro such as #if DEBUG is to set some custom Swift Compiler flags. More info in this answer: https://stackoverflow.com/a/166269/

+26
Nov 20 '15 at 15:42
source share

The modern version of Swift, taking into account simulators (based on the accepted answer):

 private func isSimulatorOrTestFlight() -> Bool { guard let path = Bundle.main.appStoreReceiptURL?.path else { return false } return path.contains("CoreSimulator") || path.contains("sandboxReceipt") } 
+8
Aug 16 '16 at 21:10
source share

This also works:

 if NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") != nil { // TestFlight } else { // App Store (and Apple reviewers too) } 

Found in Detects if iOS app loads from Testflight from Apple

+4
May 02 '15 at 20:03
source share

There is one way to use it for my projects. Here are the steps.

In Xcode, go to the project settings (project, not goals) and add the beta configuration to the list:

enter image description here



Then you need to create a new scheme that will run the project in the beta configuration. To create a diagram, go here:

enter image description here



Name this circuit as you like. You must edit the settings for this scheme. To do this, click here:

enter image description here



Select the Archive tab in which you can choose Build configuration

enter image description here



Then you need to add the Config key with the value $(CONFIGURATION) list of properties of the project information, for example:

enter image description here



Then this is just a question of what you need in the code to do something specific for the beta build:

 let config = Bundle.main.object(forInfoDictionaryKey: "Config") as! String if config == "Debug" { // app running in debug configuration } else if config == "Release" { // app running in release configuration } else if config == "Beta" { // app running in beta configuration } 
-2
Feb 16 '17 at 12:55 on
source share



All Articles