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



in_app_purchase的新实现在Android上一切正常(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();

它就是不进去,如果我试图购买相同的产品,我会得到这个错误:

对于相同的产品标识符,存在一个挂起的事务。请要么等待它完成,要么使用手动完成completePurchase避免边缘情况

您需要调用_inAppPurchase.completePurchase(purchase);来完成它。这里的代码:

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

您还需要在每次打开应用程序时调用它,以确保所有付款都已完成,这非常重要,请记住在调用它之前检查purchase.pendingCompletePurchase

顺便说一句,我更喜欢flutter_inapp_purchase而不是in_app_purchase,因为我在iOS中也遇到了一些意想不到的问题。

我在回购上打开了一个票证,它在1.0.9版本上被修复:https://github.com/flutter/flutter/issues/89950

最新更新