Flutter:获取过去在 iOS 上的购买记录

Flutter: get past purchases on iOS

Android 上的一切都在使用 in_app_purchase (https://pub.dev/packages/in_app_purchase) 的新实现,但在 iOS 上我没有得到过去的购买。根据文档,我没有看到任何特别之处。

我的代码是:

final Stream<List<PurchaseDetails>> purchaseUpdated =
          inAppPurchase.purchaseStream;

      _subscription = purchaseUpdated.listen((purchaseDetailsList) {
        if (purchaseDetailsList.isEmpty) {
          Provider.of<AdState>(context, listen: false).toggleAds(context, true);
        } else {
          Provider.of<AdState>(context, listen: false)
              .toggleAds(context, false);
          this.purchases.addAll(purchaseDetailsList);
          listenToPurchaseUpdated(purchaseDetailsList);
        }
      }, onDone: () {
        _subscription.cancel();
      }, onError: (error) {
        // handle error here.
      });

      inAppPurchase.restorePurchases();

它就是进不去,如果我尝试购买相同的产品,我会收到此错误消息:

There is a pending transaction for the same product identifier. Please either wait for it to be finished or finish it manually using completePurchase to avoid edge cases

您需要致电_inAppPurchase.completePurchase(purchase);才能完成。 Code here:

if (purchase.pendingCompletePurchase) {
  _inAppPurchase.completePurchase(purchase);
}

你还需要在每次打开你的应用时调用它,以确保所有支付都已完成,它很重要,调用前记得检查purchase.pendingCompletePurchase它。

顺便说一句,我更喜欢 flutter_inapp_purchase 然后 in_app_purchase 因为我在 iOS.

中也遇到了一些意想不到的问题

我在 repo 上开了一张票,它在 1.0.9 版本上得到了修复: https://github.com/flutter/flutter/issues/89950