【问题标题】:RNIap.getPurchaseHistory() always returns an empty array on iOSRNIap.getPurchaseHistory() 在 iOS 上总是返回一个空数组
【发布时间】:2020-12-03 21:29:59
【问题描述】:

RNIap.getPurchaseHistory 总是返回一个空数组。无论我是在应用程序启动时还是在购买后调用。 在componentDidMount 中,我执行以下操作:

async componentDidMount() {

  await RNIap.initConnection();

  this.purchaseUpdateSubscription = purchaseUpdatedListener(
    async purchase => {
      try {
        // send purchase to the server
        const savedPurchase = await savePurchase(purchase);

        // finish transaction if server returned truthly value
        if (savedPurchase) {
          await RNIap.finishTransaction(purchase, true);

          // always returns en empty array
          console.log('Purchase history', await RNIap.getPurchaseHistory())
        }
      } catch (e) {
        console.log('Error: ', e);
      }
    }
  });
}

buyProduct函数:

buyProduct = async productId => {
  try {
    await RNIap.requestPurchase(productId, false);
  } catch (e) {
    console.warn('Error: ', e);
  }
};

购买完成后,我会收到以下消息:

你已经准备好了。
您的购买成功
[环境:沙盒]。

也许问题出在与代码库无关的其他地方?

【问题讨论】:

    标签: ios react-native react-native-iap


    【解决方案1】:

    偶然发现我认为可能适合您的解决方案:

    将 RNIap.getPurchaseHistory() 包裹在 initConnection() 和 endConnection() 调用周围。 在请求购买历史记录之前,也许还要给 RNIap.finshTransaction 更多的时间来完成,以确保包括最新的购买。

    // CODE 
    await RNIap.initConnection();
       const purchase_history = await RNIap.getPurchaseHistory()
       console.log(purchase_history)
    RNIap.endConnection()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 2021-10-22
      • 2021-12-27
      相关资源
      最近更新 更多