Skip to content
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

loadProducts can not work as expected after upgrading iOS 14 #226

Open
hiroyaiizuka opened this issue Dec 23, 2020 · 3 comments
Open

loadProducts can not work as expected after upgrading iOS 14 #226

hiroyaiizuka opened this issue Dec 23, 2020 · 3 comments

Comments

@hiroyaiizuka
Copy link

hiroyaiizuka commented Dec 23, 2020

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

@hqdai
Copy link

hqdai commented Feb 5, 2021

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

@hiroyaiizuka
Copy link
Author

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

@hqdai
Copy link

hqdai commented Feb 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants