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 andfinishTransactionIOS()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()
-
Unmount component and call method
this.purchaseUpdateSubscription.remove() -
Go back to component with products and there is no
purchaseUpdatedListenerlogs to retry myApi and callfinishTransactionIOS()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
- Update README.md Added note about initConnection needed for listeners to work on iOS. Fixes issue: https://github.com/dooboolab/react-native-iap/issues/756#issuecomment-619019197 — committed to wootwoot1234/react-native-iap by wootwoot1234 4 years ago
- Update README.md (#1002) Added note about initConnection needed for listeners to work on iOS. Fixes issue: https://github.com/dooboolab/react-native-iap/issues/756#issuecomment-619019197 — committed to dooboolab-community/react-native-iap by wootwoot1234 4 years ago
- Update README.md (#1002) Added note about initConnection needed for listeners to work on iOS. Fixes issue: https://github.com/dooboolab/react-native-iap/issues/756#issuecomment-619019197 — committed to marzuq-adebayo-dev/React-Native-iap by marzuq-adebayo-dev 4 years ago
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(() => {