Search code examples
iostestflight

How to tell at runtime whether an iOS app is running through a TestFlight Beta install


Is it possible to detect at runtime that an application has been installed through TestFlight Beta (submitted through iTunes Connect) vs the App Store? You can submit a single app bundle and have it available through both. Is there an API that can detect which way it was installed? Or does the receipt contain information that allows this to be determined?


Solution

  • For an application installed through TestFlight Beta the receipt file is named StoreKit/sandboxReceipt vs the usual StoreKit/receipt. Using [NSBundle appStoreReceiptURL] you can look 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 is also the name of the receipt file when running builds locally and for builds run in the simulator.

    Swift Version:

    let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
    

    Also note that this does not work for Mac catalyst app, their receipt url is /Applications/<app>/Contents/_MASReceipt/receipt even on TestFlight.