react-native-iap: [iOS] - purchaseUpdatedListener does not works properly

Version of react-native-iap

v3.5.8

Version of react-native

react-native: 0.60.4

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

  • Call requestPurchase(string) method
  • Update listener triggered with my API to record purchase into my DB
  • myApi throw error and finishTransactionIOS() never called
  • unmount component with this.purchaseUpdateSubscription.remove()
  • mount component again
  • purchaseUpdatedListener() triggered and automatically call myApi and finishTransactionIOS() in callback

Actual behavior

  • Call requestPurchase(string) method

  • Update listener triggered with my API to record purchase into my DB

  • iOS native alert says “You’re all set”, “Your purchase was successfull” but my API throw error and finishTransaction() image

  • Unmount component and call method this.purchaseUpdateSubscription.remove()

  • Go back to component with products and there is no purchaseUpdatedListener logs to retry myApi and call finishTransactionIOS() in callback of myApi

If I kill and launch app again, mount component with products purchaseUpdatedListener is triggered and if myApi don’t throw error everything works fine.

On Android I don’t have this issue, purchaseUpdatedListener is triggered on component mount and there is no need to kill and launch app again.

Tested environment (Emulator? Real Device?)

real device - iPhone 8 iOS: 13.1.2

Steps to reproduce the behavior

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (5 by maintainers)

Commits related to this issue

Most upvoted comments

“react-native-iap”: “^4.4.6” “react-native”: “0.61.5” Still facing issue. On iOS, purchaseUpdatedListener only fires on app restart. Since it is on App.js. It has not been unmounted. I tried on sandbox but see no reason for it not to work Any fixes?

I am not sure if this would help, but when I faced the issue, even if the listener was on App.js it would still trigger an unmount. Try removing the code that removes the listener either way and see if that is the cause…

Did some digging in native wrapper. Forgot to call RNIap.initConnection() which triggers listener flag. Should add this note on readme as others can get confused. Thanks for the reply 😃

If anyone is having this issue, at least in the case of one-time purchases here is what I found (I only had time to test those)… I had my listener registered in a componentDidMount and them I removed it on componentWillUnmount… I removed the bit of code that removes the listeners and now it seems to pick up purchases. My guess at least is that on iOS the modal for payment somehow sends the app in a background mode and forces the component to trigger an unmount (on iOS at least) and by doing that it made the listeners disconnect.

strange things are happening to me, I have added INIT.CONNECTION

but now to the event IAP.PURCHASEUPDATELISTENER

come in many times. What’s going on?

`useEffect(() => {

    IAP.initConnection().then(()=>{

        console.log('connected store')

        IAP.getProducts(productIds).then(res => {
            setProducts(res)
        });

        IAP.purchaseUpdatedListener(
            (purchase) => {
                const receipt = purchase.transactionReceipt;
            
                if(receipt) {
                   
                    console.log('test')
               
                    IAP.finishTransaction(purchase)

                }
            },
        );


    })

 



},[])`