Search code examples
swifttestflight

Supporting different environments through TestFlight


Maybe this question is a duplicate but I can't find an answer.

My company wants to implement 3 different environments:

  • Staging: Used when developing in Xcode
  • UAT: Used when we push builds to TestFlight both internal and external.
  • Prod: Used when the app is on the App Store.

As far as I know:

#if DEBUG

it's not executed when a build is in TestFlight.

Is there a way to know when it is TestFlight or AppStore build?

Thank you


Solution

  • Update: There used to be a method to differentiate between Appstore and testflight releases but apple seems to have removed it's support and it no longer works. So, as of now we can't differentiate between Appstore and testflight installs.

    This was the method that used to work previously:

    let isTestflight = Bundle.main.appStoreReceiptURL?.path.contains("sandboxReceipt")
    

    You can use the same syntax for checking if it's Testflight or Appstore using RELEASE keyword:

    #if RELEASE
    print("RELEASE")
    #elseif DEBUG
    print("DEBUG")
    #endif