react-native-iap
react-native-iap copied to clipboard
Using hooks, getting Not initialized, Please call initConnection()
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]);
...
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)
+1
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
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
?
+1
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));
}, []);
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.
Still an ongoing issue for me, any help?
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
I can reproduce it locally using an emulated device that does not have Google Play Store/services.
Billing Services are not available on Emulators
I keep getting a lot of "Not initialized, Please call initConnection()" errors. Looks like it is an ongoing issue.
Did you call initConnection
?
Yes I did. It is there since we started using this library.
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);
}
}
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
you have to check the result of
initConnection
and wrap it in atry-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?
@andresesfm I found another issue and saw that I wasn't connected to the play store.
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, 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.