The below Code works fine for android as expected but for ios it doesn't work i tried to manage it ComponentDidUpdate but there it gets called multiple times.
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', () => {
BackHandler.exitApp();
});
RNIap.initConnection().then(() => {
RNIap.flushFailedPurchasesCachedAsPendingAndroid().catch(() => {
}).then(() => {
this.getSubscriptions();
this.purchaseUpdateSubscription = purchaseUpdatedListener(async (purchase:
InAppPurchase | SubscriptionPurchase | ProductPurchase) => {
this.setState({visibility:false})
this.purchaseConfirmed(purchase,"componentDidMount")
console.log("componentDidMount");
const receipt = purchase.transactionReceipt;
if (receipt) {
await RNIap.finishTransaction(purchase, false);
}
});
this.purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) =>
{
this.setState({visibility:false})
// console.warn('purchaseErrorListener', error);
});
})
})
}