How to know installed application is installed via TestFlight or AppStore?
Asked Answered
Y

2

8

I want to know about how to check user installed application is installed via Testflight or AppStore. So based on that I want to make some environmental change in whole application.

Is there anyway to find that by coding. Is Apple is providing any API for it?

Any help will be appreciated.

Yetta answered 19/4, 2019 at 9:28 Comment(3)
Testflight is for the beta testing.. how users can download your app from there ??Pym
Some of my testers are testing from testflight and sometimes they are downloading application from AppStore to check live application. So I want to know whether they have downloaded application from Testflight or AppStore.Yetta
Does this answer your question? How to tell at runtime whether an iOS app is running through a TestFlight Beta installDasilva
Y
9

I found little snippet about how to know if application is installed via TestFlight.

Here, appStoreReceiptURL is an instance property, which we can find from main bundle.

enter image description here

func isTestFlight() -> Bool {
    guard let appStoreReceiptURL = Bundle.main.appStoreReceiptURL else {
    return false
    }
    return appStoreReceiptURL.lastPathComponent == "sandboxReceipt"
}
Yetta answered 20/4, 2019 at 5:1 Comment(2)
Thanks - still working for me as of iOS 14 and Xcode 12.4Langill
Useful however - for those with ability to read deleted posts - it’s well worth reading @matt’s comments below.Dasilva
W
0

If you guys using React Native. You can follow the code below.

First at ios folder, let create two files:

TestFlightModule.h

#ifndef TestFlightModule_h
#define TestFlightModule_h

#import <React/RCTBridgeModule.h>

@interface TestFlightModule : NSObject <RCTBridgeModule>
@end

#endif /* TestFlightModule_h */

TestFlightModule.m

#import "TestFlightModule.h"
#import <React/RCTLog.h>

@implementation TestFlightModule

// To export a module named TestFlightModule
RCT_EXPORT_MODULE();

- (BOOL)isTestFlight {
  NSURL *appStoreReceiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
  if (!appStoreReceiptURL) {
    return NO;
  }
  return [appStoreReceiptURL.lastPathComponent isEqualToString:@"sandboxReceipt"];
}

// Export a method to check if the app is running via TestFlight
RCT_EXPORT_METHOD(checkIfTestFlight:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
  BOOL isTestFlight = [self isTestFlight];
  resolve(@(isTestFlight));
}

@end

In your YourProjectName-Bridging-Header.h. Let import the header file just created

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "TestFlightModule.h"

In your React Native project directory, run:

npx react-native link

Using:

import {
  NativeModules
} from 'react-native';

const {
  TestFlightModule
} = NativeModules;


useEffect(() => {
  TestFlightModule.checkIfTestFlight()
    .then(isTF => console.log(isTF))
    .catch(error => console.error(error));
}, []);

Clean the project and run

cd ios
pod install
cd ..
npx react-native run-ios
Whereunto answered 18/6, 2024 at 9:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.