Skip to content

Check for TestFlight build programmatically

iOS, Swift, TestFlight1 min read

Sometimes you might want to have a way to check if an app has been downloaded for TestFlight or not. A good example use case for this is if you want to only show test ads in a TestFlight version of your app.

I have shipped a few apps for iOS over the years but didn't actually realise this was possible until a few months ago. Basically all you need to do is make some checks against the app's App Store receipt to see if it contains "sandboxReceipt".

You can make a quick extension for this on Bundle, here's what the code looks like:

1extension Bundle {
2 ...
3 var isProduction: Bool {
4 #if DEBUG
5 return false
6 #else
7 guard let path = self.appStoreReceiptURL?.path else {
8 return true
9 }
10 return !path.contains("sandboxReceipt")
11 #endif
12 }

First of all, you check if the app is a debug version or not. Then you check if there is a path for the store receipt or not. Then the last step is to check if that path contains "sandboxReceipt".

So to summarize, this will return false if:

  • The app is a debug version
  • The app is a TestFlight build(the receipt path will contain "sandboxReceipt" in this case)

I opted to call this computed value 'isProduction' but you could make some tweaks to the code and change this to what suits you. So far it's working pretty well for my use case of only showing test ads in TestFlight builds.