dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.78k stars 634 forks source link

"E_IAP_NOT_AVAILABLE" when calling initConnection on react-native-iap #2084

Closed domuen closed 1 year ago

domuen commented 1 year ago

I am building a mobile app (React Native) that requires subscriptions to use. I will be using Apple/Google pay on the respective platforms. I would like to request subscriptions with the react-native-iap library for React Native

I get the error "E_IAP_NOT_AVAILABLE" when calling the initConnection method from the react-native-iap library. I get this on both iOS and Android

IMG_1225 Screenshot from 2022-10-31 00-01-20

My setup: expo@46 react@18 react-native@0.69.6 react-native-iap@12.3.2

I have tried downgrading react-native-iap to versions 8.0.1 and 7.0.3 (and reinstalling modules) with the same result.

I can't seem to find any questions similar to this issue. Any ideas would be appreciated

andresesfm commented 1 year ago

For Android, are you running on the Emulator? (It only works on physical devices). For Ios, what device/iOS version are you testing with? What Storekit mode are you using?

domuen commented 1 year ago

I am testing on physical devices. I am using an iPhone 13 on iOS 15 and Samsung S22 on android 12. I am not using StoreKit. I am going to create subscriptions to the ones I created on AppStore Connect. I can't use any of the methods though because initConnection throws that exception

andresesfm commented 1 year ago

@babydough The thing that comes to mind is that you might be using setup({storekitMode: 'STOREKIT2_MODE'}) on a device with older iOS. Another option is that IAP purchases are not available on those devices. Are you able to purchase on other apps?

LorienHW commented 1 year ago

same thing was happening to me - after upgrading from version 6 - in my case the error was being thrown from calling flushFailedPurchasesCachedAsPendingAndroid on ios

LorienHW commented 1 year ago

and on android it throws this error when calling clearProductsIOS

andresesfm commented 1 year ago

That makes sense. Thank you @LorienHW for your help

domuen commented 1 year ago

I am not calling the setup, flushFailedPurchasesCachedAsPendingAndroid or clearProductsIOS methods at all. All I am doing is calling initConnection in my useEffect in App.tsx on app launch, which is throwing that exception

Here is my entire App.tsx component

import React from "react";
...

export default () => {

  const checkSubscription = async () => {
    try {
      const skus: string[] = Platform.OS === "ios" ?
        ["...", "..."] :
        ["...", "..."];

      const subscriptions = await getSubscriptions(skus);
      console.log(subscriptions);
    } catch (e) {
      console.error(e);
    }
  };

React.useEffect(() => {
    initConnection()
      .then((c) => console.log("connected: ", c))
      .catch((e) => console.log("connection error:", e));
  }, []);

  return <React.Fragment>
    ...
  </React.Fragment>
}
LorienHW commented 1 year ago

you might go into node_modules/react-native-iap/src/internal/platform.ts into the method checkNativeIOSAvailable and see which condition is causing it to error - either !RNIapIos or !isStorekit2Avaiable() must be returning true. if RNIapIos is not defined maybe the native module is not present for some reason. You can go in and put some console.log statements in that file and they will print out in your javascript console when you run it. Dumb question but you did run pod install right?

domuen commented 1 year ago

@LorienHW I just did what you said and logged those values. RNIapIos was null and isStorekit2Avaiable() returned false. This is on the latest release. Also note this error happens on Android as well. Do you think this could be an issue with Expo Go or something? I'm not very familiar with native modules or how they interact with Expo

LorienHW commented 1 year ago

yeah, so for me RNIapIos is defined, so it never checks isStorekit2Avaiable(). i do think its likely that this is somehow related to Expo, however i have never used Expo so i dont know really what it would be. but it kind of seems like the native module has maybe not been built in

andresesfm commented 1 year ago

If you are using expo, take a look at: https://stackoverflow.com/a/73159706/570612

anishamalde commented 1 year ago

Is there any way to get around the error if you are using expo and don't want to build the project every-time?

domuen commented 1 year ago

Just so everyone is aware, I ended up switching to RevenueCat and now use the react-native-purchases library. It is true that I have to build my app every time I want to test a change, which definitely is annoying.

@anishamalde I usually have to comment out any code before I test locally on both libraries. It won't work with Expo Go. At least the code is pretty straight forward once you have everything setup

iasreact1 commented 1 year ago

@LorienHW @domuen @andresesfm i used react-native-iap -12.7.2 and i got similar error and got RNIapIos is null and isStorekit2Availabel() is false ...what is the solutions ? please help Sir...

andresesfm commented 1 year ago

Could be a problem with pod install?

ggchicote commented 1 year ago

@iasreact1 did you fill up the Agreements, Tax, and Banking section? It might be the problem. Remember that it takes till 24hs to be accepted.

YASH6004 commented 9 months ago

this worked for me : https://github.com/dooboolab-community/react-native-iap/issues/1404#issuecomment-1794639457

aleksandarbos commented 9 months ago

If you are using expo, take a look at: https://stackoverflow.com/a/73159706/570612

yup, "expo go" won't work. expo development (native) build is required. thanks @andresesfm

question: is there a way to handle this error somehow so we can keep using expo go? current solution: grind

import Constants from 'expo-constants';
const isExpoGo = Constants.appOwnership === 'expo';

...
// App.js
export default isExpoGo ? App : withIAPContext(App);

...
// Somefile.js
if (!isExpoGo) {
    const { connected, availablePurchases, getAvailablePurchases } = useIAP();
    ...

is there better way to handle this, maybe not to throw that error out if expo go is detected?

pashanhenlei commented 9 months ago

Could be a problem with pod install?

Yes, in my case, I just re-run 'pod install' and make sure the output contains "Installing RNIap", and the error is gone.

wesamodeh commented 5 months ago

SOLVED

i added this in my initConnection : RNIap.purchaseUpdatedListener(purchase => { RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken); });

fixed when i add a condition :

if (Platform.OS === 'android') { RNIap.purchaseUpdatedListener(purchase => { RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken); }); }

Muhammad-Ibrahim-Amjad64 commented 4 days ago

I'm using an iOS emulator with iPhone 14 and iOS 17.5 but still encountering the E_IAP_NOT_AVAILABLE error.