react-native-in-app-utils icon indicating copy to clipboard operation
react-native-in-app-utils copied to clipboard

loadProducts can not work as expected after upgrading iOS 14

Open hiroyaiizuka opened this issue 4 years ago • 3 comments

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.

スクリーンショット 2020-12-23 16 55 20

hiroyaiizuka avatar Dec 23 '20 07:12 hiroyaiizuka

I'm getting this issue too on simulator, device is working fine? Any new update on this :D

hqdai avatar Feb 05 '21 08:02 hqdai

Yeah, i could finally work fine both in simulators and device with above changes.

hiroyaiizuka avatar Feb 05 '21 08:02 hiroyaiizuka

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: Screen Shot 2021-02-05 at 15 55 59

hqdai avatar Feb 05 '21 08:02 hqdai