React-native-iap: RNIap.requestPurchase is not responding in iOS

Created on 13 May 2020  ·  11Comments  ·  Source: dooboolab/react-native-iap

Version of react-native-iap

4.4.8

Version of react-native

0.61.5

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

iOS

Expected behavior

await RNIap.requestPurchase(sku, false)
console.log('REQUEST OVER') 

REQUEST OVER to be printed.

Actual behavior

In device i use sandbox tester account, it is responding and working well. But with any other devices or simulator it is not responding or resolving. This is vital since during app review, Apple keep rejecting my application with reason of tapping in BUY is not responding.

There is no problem about RNIap.getProducts(itemSkus)

Tested environment (Emulator? Real Device?)

Real Device and Simulator

Steps to reproduce the behavior

 async componentDidMount() {
    RNIap.getProducts(itemSkus)
      .then((products) => {
        this.setState({ products: products })
      })
      .catch((error) => {
        console.log(error.message)
      })
  }
requestPurchase = async (sku) => {
    try {
      await RNIap.requestPurchase(sku, false)
      console.log('REQUESTED OVER')
    } catch (err) {
      console.warn(err.code, err.message)
    }
}

render() {
 const { products } = this.state
 return (
  <View>
    {products.map((p, i) => { return (
       <TouchableWithoutFeedback onPress={() => this.requestPurchase(p.productId)}>
          <Text> BUY </Text>
       </TouchableWithoutFeedback> ) })}
 </View>)
🚶🏻 stale

Most helpful comment

I had the same problem and @Panda313 suggestion to add await RNIap.initConnection() in componentDidMount worked.
Too bad this is not better documented...

All 11 comments

Same here, however it seems to work on Android.

I may have fixed it by adding

const result = await RNIap.initConnection();
await RNIap.consumeAllItemsAndroid();
console.log('result', result);

At the begining of componentDidMount ;

Let me know if that help

@hyochan Have you found a resolution to this? I am also experiencing the same problem in iOS. Its extremely frustrating, and I can't get past app review because calling RNIap.requestPurchase doesn't respond with the alert either promoting the user to agree to the subscription terms or confirming that the subscription is already active. If I force close the app and try it again, sometimes it works. I don't know if there is a problem with the sandbox or this library.

@smarttouchtechnology Have you called initConnection? This is needed from 4.4.5.

It may be hard for @smarttouchtechnology to read the answer below that "solve" the "problem" ;)

I had the same problem and @Panda313 suggestion to add await RNIap.initConnection() in componentDidMount worked.
Too bad this is not better documented...

@Panda313 ... You just saved me1 week sleepless night of apple rejection

Could someone add this to the documentation so more people don't run into this issue? I'm not sure the best way to add it.

EDIT: Added here. #1088.

Feel free to review (I'm not confident I did it right.)

I may have fixed it by adding

const result = await RNIap.initConnection();
await RNIap.consumeAllItemsAndroid();
console.log('result', result);

At the begining of componentDidMount ;

Let me know if that help

For iOS, I didn't have any response from requestSubscription. I tried adding await RNIap.initConnection(); in front of RNIap.requestSubscription and it worked for me. Now I am receiving purchase objects in listeners in the root of the app. And it also proceeds further down the code after it resolves either in error or in successful response.

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

Was this page helpful?
0 / 5 - 0 ratings