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:
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