-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors with calling 'await RNIap.prepare();' for in app purchase in Android #168
Comments
@SlZeroth What is the version of your react-native? I'll watch this one tommorow. It's 12 PM in here, need to go to sleep :( |
@dooboolab my react native version is 0.54 . thank you :) |
I'm having the same issue, appears to happen when we reset the app state (user signs in or out of Facebook and we need to re-sync all data). We essentially end up in a state where we call prepare for a second time. The error in the console is: Running RN 0.55.3 and RN IAP 1.0.5. EDIT: This is on the simulator, where the first call to prepare fails due to Store not being properly set up. |
On a real device this results in a slightly different error, |
Workaround, track if |
@pehagg hmm .... I got same error The callback prepare() exists in module RNIapModule, but only one callback may be registered to a function in a native module.. on real device , where console did you saw "Error: The service is disconnected (check your internet connection." error ?? |
@pehagg I tested react native iap module after upload alpha APP. |
I am getting the same error:
dependencies
According to this:
|
ok, basically there is a pass that a promise can be called multiple times. In case it hits this line, the same promise will be invoked twice. This needs to be fixed it seems? It seems I need to call endConnection()? I did not know this is a requirement. Why don't we just call it internally every time before we start billing? |
@wasedaigo Sounds good if not calling |
As long as it is clearly state in the docs calling endConnection is fine. I saw other libraries did open/close for this as well. As long as we can avoid this magical error from appearing we should be able to close this issue |
I am still having this issue and not much luck fixing it by calling
import * as RNIap from 'react-native-iap'
await RNIap.initConnection()
await RNIap.getProducts([SKU])
const products = await RNIap.getAvailablePurchases()
// some logic with the purchases
await RNIap.endConnection()
await RNIap.initConnection()
await RNIap.getProducts([SKU])
await RNIap.buyProduct(SKU)
await RNIap.endConnection() And I have also tried calling In both cases, everything works, but later on there is always a crash (ie. when the app is backgrounded), and the stack is the exact same as posted above. Using version 2.2.2 on Android. @dooboolab can we re-open this or point me in the right direction please? |
@nkov If you have some scenes which screen is holding |
I am having the same issue too. I coded in similar way as @nkov in |
@punksta |
I understand it, it's clear. however calling initConnection second time after endConnection sometimes crashes the app. I meant that the flow is not very clear. |
We're still experiencing issues with 2.3.12. The only way for me to get rid of the random errors we got because the connection was not open anymore or wasn't prepared, was to init the connection every time a purchase is being made and close it once the purchase is completed. However, this has now lead us to see these crashes in our logs:
Before making this change we initialised the connection every time the user arrived in the IAP screen, but as said, this wasn't enough, we got all kinds of random exceptions from RNIap. I'm running out of options and will need to start to look for another library if this cannot be sorted out. |
@pehagg You're missing |
I call endConnection in the finally block of a try-catch-finally, where the init, purchase, and consumption is all done in the try block. |
show us the code so we can figure out |
Here's the code. The only plausible explanation I can come up with is that there's an exception that is swallowed up by RNIap, which would explain that the finally block doesn't get called at all, or then the actual endConnection call fails. try {
await RNIap.initConnection();
const iap = <redacted> // find the IAP matching productId
if (iap) {
const purchase = await RNIap.buyProduct(productId);
await RNIap.consumePurchase(purchase.purchaseToken);
<redacted>
}
} catch (error) {
<redacted>
} finally {
try {
await RNIap.endConnection();
} catch (error) {
<redacted>
}
} |
Just noticed that some of the crashes are coming from another part of the code, where we initialise the IAPs for the first time. The structure is the same, without the purchase and consumption. Here's a stack trace of such a case:
In this case we got |
I'm having this issue as well. I'm not sure if this is helpful or not, but after looking at quite a few logs from crashlytics, it seems to occur after a user abandons the app for a while - not exiting, but maybe leaving it running in the background. I'm using the edit: I'm realizing now that they could just be exiting the app at a later time |
Hi, this is a very interesting issue and one that I am having also that I have referenced here: #325 I was just wondering if this discussion was still open or if anyone has a solution. |
Version of react-native-iap
the lastest version for now
Platforms you faced the error (IOS or Android or both?)
Android
Expected behavior
calling 'await RNIap.prepare();' succesfully
Actual behavior
I got an error message saying 'Illegal callback invocation from native module. This callback type only permits a single invocation from native code'
I have an error at the 347 line of RnlapModule.java when I use RNIapModule.java
'resolvePromisesForKey(PROMISE_PREPARE, null);' This is 347 line. I mean that when I try to implement it, I have an error.
Tested environment (Emulator? Real Device?)
Real Device
Steps to reproduce the behavior
The text was updated successfully, but these errors were encountered: