React-native-iap: Cannot connect to iTunes Store - should I be worried?

Created on 2 Apr 2020  路  20Comments  路  Source: dooboolab/react-native-iap

Version of react-native-iap

4.4.2

Version of react-native

0.61.4

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

iOS

Expected behavior

No error should occur since I'm checking for network access and then attempt to connect to the store. So unless the App Store is unavailable, I wouldn't expect this to happen.

Is this normal? Should I expect this to happen from time to time?

Actual behavior

I'm getting error "Cannot connect to iTunes Store"

Tested environment (Emulator? Real Device?)

I haven't been able to reproduce the problem. I'm seeing this in logs from the production app, and quite a lot of people seem to be getting this error.

Code

  initiatePurchase = async () => {
    try {
      const netState = await NetInfo.fetch()

      if (!netState.isConnected) {
        return this.stores.ui.alert('Purchase failed', connectionFailureMessage)
      }

      await requestPurchase(fullGameSku, false)
    } catch (error) {
      logger.warn(error)
    }
  }
馃摫 iOS 馃檹 help wanted

All 20 comments

Looks like this is on Apple's side and I found few issues.

Any news on this? I cannot connect, calling getAvailablePurchase() and loggin in with sandbox account on iPhone XS simulator results in Cannot connect to iTunes Store promise rejection, XCode console just logs restoreCompletedTransactionsFailedWithError

When you get the Cannot connect to iTunes Store error do you also see the error code that comes along with it? The SDK will return Cannot connect to iTunes Store a generic error for various reasons. Below are some examples that might help you narrow down the issue.

  1. Code = E_Unknown => something went wrong (could be on apple's side)
  2. Code = E_USER_CANCELLED => User cancelled the transaction (not an error but this gets returned.

@dan10gc The error object seems to only return the message, no code. Are you sure requestPurchase returns those codes? I've only seen them in purchaseErrorHandler.

The last 10 days I've seen 15-25 "Cannot connect to iTunes Store" errors daily, but only 5 or 6 triggers from purchaseErrorHandler.

Payment is also well made in TestFlight.
However, it is rejected.
There is an error in the simulator. (Cannot connect to iTunes Store )
What can I do to solve this issue?

@AdamGerthel yes requestPurchase should return the code if you log error.code inside your try/catch. This also helps narrow down the issue in purchaseErrorHandler.

initiatePurchase = async () => {
    try {
      const netState = await NetInfo.fetch()

      if (!netState.isConnected) {
        return this.stores.ui.alert('Purchase failed', connectionFailureMessage)
      }

      await requestPurchase(fullGameSku, false)
    } catch (error) {

      logger.warn(error, error.code)
    }
  }

Can I test IAP in a simulator?

@anastely for android and iOS you need to use an actual device, you are unable to use an emulator or simulator to test purchases.

@dan10gc sadly I don't have "iPhone", So if you don't mind
Can you help me to write code just subscribe in Paid Plan "Non-Consumable Type" Because i don't know what's going on when i write code without seeing anything "on the fly"

my case is
I have a screen contain that's should get the Price from App store "6.99$"

And when user click to subscribe it's should be paid to apple, If success i will make redux stuff "access to full features"

So can you help?
Screenshot example

--
What i tried "before know i can't use simulator"

Code


export default class PurchaseScreen extends Component {
  componentDidMount() {
    this.getPurchases();
  }
  getPurchases = async () => {
    try {
      const init = await RNIap.initConnection();
      console.log('init?', init);
      const availablePurchases = await RNIap.getAvailablePurchases(items);
      console.log('availablePurchases', availablePurchases);
    } catch (err) {
      console.warn(err);
    }
  };


subscribe = ()=>{
    ...
}

  render() {
    return (

  <TouchableOpacity onPress={()=>this.subscribe()} style={styles.btn}>
       <Text style={styles.lable}>Subscrib</Text>
    </TouchableOpacity>
   )
  }

}

@dan10gc iOS: Can you test on device but with sandbox account on local debug or do you need TestFlight release? I know UX is different but just to test the correctness.

On Android I'm trying to test through Play Store internal test release.

But (@anastely) if approval for new builds requires at least one week these times, I guess the best bet for first-timers like me would be installing CodePush... prior to that, thoroughly studying the example app provided in this repo. Also server-side receipt validation is needed for Android at least, as I understand.

@DavideValdo Hmm,I don't have enough time, I'm in the deadline :(,

If I will improvise, then upload app to test flight, In my case "Non-Consumable Type" What should exactly i do

After getAvailablePurchases() response can i got from it a price?

and in the subscribe button which function should i call requestPurchase()?

@DavideValdo for iOS you can test with a sandbox account on local debug as long as you are using a real device and not a simulator. Also you don't really need a sandbox account when testing locally, I believe apple will use your apple ID and allow it to be used as a sandbox account.

@anastely only use getAvailablePurchases() if restoring a subscription or a purchase not while purchasing an item.

@anastely I am unable to assist you with the code for purchasing an iOS system in this thread. pleas post it on stack overflow and tag me with the same user name and I will help you. I do not want to add to this tread unless it pertains to the original question.

@dan10gc and @anastely Uhm - you guys have kind of hi-jacked this issue 馃檭

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.

We are also seeing the cannot connect error. @AdamGerthel have you found a solution?

@L-Yeiser I think I solved it by making sure I'd run initConnection() before doing any other requests.

I still get it in the logs from time to time, but it's very rare, only a couple of times per month (with ~15K downloads per month).

@L-Yeiser I think I solved it by making sure I'd run initConnection() before doing any other requests.

I still get it in the logs from time to time, but it's very rare, only a couple of times per month (with ~15K downloads per month).

This worked for me as well. Thanks for the fix.

Hello, i was facing issue of in-app is not working in iOS 14 and getting Cannot connect to iTunes Store in iOS below 14 version, then i uploaded to TestFlight and checked after that and got in-app working. You can try that too if you can.

Also to let you know that initConnection() doesn't worked for me at all.

Was this page helpful?
0 / 5 - 0 ratings