react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

Using hooks, getting Not initialized, Please call initConnection()

Open roblingle opened this issue 2 years ago • 10 comments

Please use Discussion board if you want get some help out of it. Please report issue if there is a bug.

Version of react-native-iap

7.5.0

Version of react-native

0.63.4

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

Android only

Expected behavior

I should not have to call initConnection using hooks

Actual behavior

After connected is true we getSubscriptions(ids) but it throws an error Not initialized, Please call initConnection()

Tested environment (Emulator? Real Device?)

Real device

Steps to reproduce the behavior

App.js is wrapped and exported as withIAPContext(App)

The code:

export const useSubscription = () => {
  // initConnection();  // <-- In dev, this will avoid the error. Not in production.
  const {
    connected,
    subscriptions,
    finishTransaction,
    getSubscriptions,
    currentPurchase,
    currentPurchaseError,
  } = useIAP();
  
  ...
  
  useEffect(() => {
    if (connected) {
      getSubscriptions(subscriptionIds).catch((err) => { // <-- Error here
        Sentry.Native.captureException(err)
      });
    }
  }, [connected]);

 ...

roblingle avatar Oct 06 '21 01:10 roblingle

I got the same issue. With version of react-native-iap 7.5.0 Version of react-native 0.65.1

Error happen when call purchaseUpdateProduct = IAP.purchaseUpdatedListener(inAppPurchase => {}) after connect success

Possible Unhandled Promise Rejection (id: 0): Error: Not initialized, Please call initConnection() Error: Not initialized, Please call initConnection() at Object.promiseMethodWrapper [as startListening] (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:2573:36) at Object.purchaseUpdatedListener (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:145524:68) at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:144029:55 at invokePassiveEffectCreate (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:17364:26) at Object.invokeGuardedCallbackProd (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:3915:16) at invokeGuardedCallback (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:4019:37) at flushPassiveEffectsImpl (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:17434:15) at unstable_runWithPriority (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:55160:18) at runWithPriority (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:7733:16) at flushPassiveEffects (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.booklover&modulesOnly=false&runModule=true:17323:20)

ThuyDang88 avatar Oct 23 '21 08:10 ThuyDang88

+1

hiroyaiizuka avatar Oct 25 '21 07:10 hiroyaiizuka

I thought with hooks it wasn't mandatory to initConnection and that hooks took care of this part. But I'm not sure.

Anyway, purchases seem to work on emulator and real devices, but I keep getting a lot of Not initialized, Please call initConnection() errors. I don't understand what should I do to fix this error. Documentation about using hooks is not very clear. I can't reproduce this error in emulator.

I'm using react-native: 0.66.1 and react-native-iap: 7.5.0

jeremyhalin avatar Nov 20 '21 21:11 jeremyhalin

I wonder if it's related to https://github.com/dooboolab/react-native-iap/issues/1562

Any update on this? What should be done to fix error on 7.5.1?

jeremyhalin avatar Nov 27 '21 10:11 jeremyhalin

+1

okcompewter avatar Dec 11 '21 23:12 okcompewter

Seems to happen on emulated devices that do not have the Play Store and when using hooks implementation.

I'm able to no longer get this LobBox warning by updating \src\hooks\withIAPContext.js, line 102, by catching the error, but is there a better way/place to implement this?

        useEffect(function () {
            initConnection().then(setConnected).catch(error => console.log(error));
        }, []);

okcompewter avatar Jan 18 '22 05:01 okcompewter

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.

stale[bot] avatar Apr 27 '22 18:04 stale[bot]

Still an ongoing issue for me, any help?

okcompewter avatar Apr 27 '22 18:04 okcompewter

I am seeing these errors in production for a subset of users. Has anyone been able to reproduce this locally? I'm struggling to emulate this

tpagram-pwc avatar Jun 18 '22 06:06 tpagram-pwc

I can reproduce it locally using an emulated device that does not have Google Play Store/services.

okcompewter avatar Jun 18 '22 06:06 okcompewter

Billing Services are not available on Emulators

andresesfm avatar Sep 01 '22 23:09 andresesfm

I keep getting a lot of "Not initialized, Please call initConnection()" errors. Looks like it is an ongoing issue.

rajeshrthl avatar Sep 20 '22 01:09 rajeshrthl

Did you call initConnection ?

andresesfm avatar Sep 22 '22 19:09 andresesfm

Yes I did. It is there since we started using this library.

rajeshrthl avatar Sep 28 '22 20:09 rajeshrthl

Same, I'm using version 7.1.0 but it's not with hooks

  async componentDidMount() {
    await RNIap.initConnection();

    try {
      await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
      this.purchaseUpdateSubscription = this.connectUpdateSubscription();
      this.purchaseErrorSubscription = this.connectErrorSubscription();
    } catch (error) {
      console.error(error);
    }
  }

danicunhac avatar Sep 29 '22 11:09 danicunhac

you have to check the result of initConnection and wrap it in a try-catch as it might not be available on a device or it may fail to initialize

andresesfm avatar Sep 29 '22 17:09 andresesfm

you have to check the result of initConnection and wrap it in a try-catch as it might not be available on a device or it may fail to initialize

That's what I did actually, I put it inside the try-catch below and it shows me the following

E_NOT_PREPARED Not initialized, Please call initConnection()

Should I be using a real device to test/develop using this library?

danicunhac avatar Sep 30 '22 11:09 danicunhac

@andresesfm I found another issue and saw that I wasn't connected to the play store.

danicunhac avatar Sep 30 '22 12:09 danicunhac

Sorry but why this thread is closed? This error still appears in production and in development on real device. And I don't see any explanation or working workaround here. Moreover most of devices with this error use Google Services and has Play Market also. So I don't think that this error depends only on physical device or play services.

GeorgeVidIq avatar Jan 16 '23 13:01 GeorgeVidIq

@GeorgeVidIq, it is closed because:

  • It was stale (see above),
  • There are possible causes such as @danicunhac 's comment or my comment about Play Services not available
  • This was reported on an old version of the library.

If you have any more information to contribute such as the return code when you call initConnection and have updated to a recent version of the library, please create a new ticket with all the details. otherwise, it's very difficult to guess what your situation is.

andresesfm avatar Jan 17 '23 18:01 andresesfm