Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
getPurchaseHistory()在iOS上始终返回空数组_Ios_React Native_React Native Iap - Fatal编程技术网

getPurchaseHistory()在iOS上始终返回空数组

getPurchaseHistory()在iOS上始终返回空数组,ios,react-native,react-native-iap,Ios,React Native,React Native Iap,RNIap.getPurchaseHistory始终返回空数组。无论我是在应用程序启动时还是在购买后调用。 在componentDidMount中,我执行以下操作: async componentDidMount() { await RNIap.initConnection(); this.purchaseUpdateSubscription = purchaseUpdatedListener( async purchase => { try {

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 = async productId => {
  try {
    await RNIap.requestPurchase(productId, false);
  } catch (e) {
    console.warn('Error: ', e);
  }
};
购买时,我收到以下信息:

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


也许问题可能在与代码库无关的另一个地方?

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

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

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