react-native-in-app-utils
react-native-in-app-utils copied to clipboard
loadProducts can not work as expected after upgrading iOS 14
version
"react-native-in-app-utils": "^6.0.2",
"react-native": "0.61.5",
Overview
Before upgrade iOS 14, our code worked fine as follows.
if (!await PurchaseService.canMakePayments) {
...
}
await PurchaseService.loadProducts()
...
await PurchaseService.purchaseProduct(productId)
const canMakePayments = () => {
return new Promise(resolve => {
InAppUtils.canMakePayments(response => resolve(response))
})
}
const loadProducts = () => {
return new Promise((resolve, reject) => {
InAppUtils.loadProducts(products, (error, response) => {
if (error) {
return reject(error)
}
return resolve()
})
})
const purchaseProduct = (productId: string) => {
return new Promise((resolve, reject) => {
InAppUtils.purchaseProduct(
productId,
(error, response: PurchaseProductResponse) => {
if (error) {
reject(error)
}
if (response && response.productIdentifier) {
resolve(response)
}
},
)
})
}
But after upgraded iOS14, ios subscription pop up did not show up. It seems loadProducts() failed and purchaseProduct() did not call.
I checked this issue, i upgraded this library from 6.0.1
to 6.0.2
But above code leaded to uncontrollable timing of ios subscription popup.
After changed like below, it worked perfectly.
if (!await PurchaseService.canMakePayments) {
...
}
await PurchaseService.purchaseProduct(productId)
const purchaseProduct = (productId: string) => {
return new Promise((resolve, reject) => {
InAppUtils.loadProducts(products, (error, response) => {
if (error) {
reject(error)
}
return InAppUtils.purchaseProduct(productId, (error, response) => {
// NOTE for v3.0: CurrentUser can cancel the payment which will be available as error object here.
if (error) {
reject(error)
}
if (response && response.productIdentifier) {
resolve(response)
}
})
})
})
}
Call purchaseProduct method inside loadProducts callbacks.
It seems there are some related sentences in README, but i think sample code(purchaseProduct()) should be fixed.

I'm getting this issue too on simulator, device is working fine? Any new update on this :D
Yeah, i could finally work fine both in simulators and device with above changes.
Yeah, i could finally work fine both in simulators and device with above changes.
Oh, Could you share more detail on your solution? When calling InAppUtils.loadProducts(productIds, (error, products) => { console.log( error); });
Error always show: