flutter IAP如何 "Restore Purchases"

标签 flutter in-app-purchase restore

我正在使用 flutter_inapp_purchase对于我的 flutter 应用程序的非消耗品 IAP。对于IOS,它确实需要包含一个“恢复购买”的功能,让用户可以恢复之前购买的应用内购买。我可以知道如何创建“恢复”按钮并在用户点击“恢复”按钮时启动恢复过程吗?

  Future<Null> _buyProduct(IAPItem item) async {
    try {
      PurchasedItem purchased= await 
  FlutterInappPurchase.buyProduct(item.productId);
      print('purcuased - ${purchased.toString()}');
    } catch (error) {
      print('$error');
    }
  }

  Future<Null> _getProduct() async {
    List<IAPItem> items = await FlutterInappPurchase.getProducts(_productLists);
    for (var item in items) {
      print('${item.toString()}');
      this._items.add(item);
    }

    setState(() {
      this._items = items;
    });
  }

最佳答案

对于使用官方 flutter 开发包的开发者 https://pub.dev/packages/in_app_purchase :

恢复购买(iOS 非消耗品、自动续订订阅或 非续订订阅)只是调用

Future<QueryPurchaseDetailsResponse> queryPastPurchases

在后台调用

_observer.getRestoredTransactions

您在这里应该做的是迭代所有状态为 PurchaseStatus.purchased 或 Purchase.error 的购买并调用

InAppPurchaseConnection.instance.completePurchase(purchase);

然后通过 Apple 验证收据并交付购买的商品

taken from class InAppPurchaseConnection:

/// You are responsible for completing every [PurchaseDetails] whose /// [PurchaseDetails.status] is [PurchaseStatus.purchased] or /// [[PurchaseStatus.error]. Completing a [PurchaseStatus.pending] purchase /// will cause an exception. /// /// This throws an [UnsupportedError] on Android.

  • If a purchase is not completed ([completePurchase] is not called on the purchase object) from the last app session. Purchase updates will happen when a new app session starts instead.

您可能无论如何都会在应用启动时这样做,但 Apple 现在要求为所有非消耗品和自动更新的应用内产品恢复购买选项,否则您的应用将在审核过程中被拒绝。

https://developer.apple.com/documentation/storekit/in-app_purchase/offering_completing_and_restoring_in-app_purchases

If your app sells non-consumable, auto-renewable subscription, or non-renewing subscription products, you must provide a UI that allows them to be restored. Your customers expect your content to be available on all their devices and indefinitely; see In-App Purchase for more information.

关于 flutter IAP如何 "Restore Purchases",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53776179/

相关文章:

android - 是日志 drom dart :developer are visible in release mode of flutter app?

flutter - 要在 Flutter 中列出的复杂字符串

unity-game-engine - Unity 的 CrossPlatformValidator 到底在哪里?

iphone - 应用内购买,多个具有不同持续时间的自动续订订阅

mysql - 如何从包含多个数据库的 mysqldump 中恢复一个数据库?

flutter - 如何在 Flutter 中点击其他小部件时打开 DropdownButton?

ios - 升级我的 flutter 版本后无法构建 iOS 应用程序

ios - 我将如何为 SKPaymentQueue 使用未弃用的 API?

postgresql - 恢复 Postgresql 转储文件

svn - 从 SVN 恢复已删除文件的正确方法是什么?