flutter 在应用程序订阅中购买导致 iOS 崩溃

问题描述 投票:0回答:1

我正在尝试将应用程序订阅集成到我的应用程序中,我正在使用 in_app_purchase 包https://pub.dev/packages/in_app_purchase。我按照这里的教程进行操作:https://www.youtube.com/watch?v=NWbkKH-2xcQ。 Android 中一切都运行良好。但是,每次我在 iOS 中调用 _buyProduct 方法时,应用程序都会崩溃,但付款单会在主屏幕中弹出。有人面临同样的事情或者有人有任何建议吗?短暂性脑缺血发作。

  Future<void> _initialize() async {
    // Check availability of In App Purchases
    _available = await _iap.isAvailable();

    if (_available) {
      await _getProducts();
      await _getPastPurchases();
      _verifyPurchase();

      // Listen to new purchases
      _subscription = _iap.purchaseStream.listen((data) {
        // Create a temporary list to store the new purchases
        List<PurchaseDetails> newPurchases = List.from(data);

        // Update the UI after the iteration has completed
        setState(() {
          _purchases.addAll(newPurchases);
          _verifyPurchase();
        });
      });
    }
  }

  // Validate purchase

  // Get all products available for sale
  Future<void> _getProducts() async {
    Set<String> ids = _productIDs.toSet();
    ProductDetailsResponse response = await _iap.queryProductDetails(ids);

    setState(() {
      _products = response.productDetails;
    });
  }

  // Gets past purchases
  Future<void> _getPastPurchases() async {
    // Listen to purchase updates
    _iap.purchaseStream.listen((purchases) {
      List<PurchaseDetails> newPurchases = [];

      // Iterate over the purchases and filter out the iOS purchases if needed
      for (PurchaseDetails purchase in purchases) {
        if (Platform.isIOS) {
          _iap.completePurchase(purchase);
        }
        newPurchases.add(purchase); // Add the purchase to the temporary list
      }

      // Update the _purchases list after the iteration has completed
      setState(() {
        _purchases.addAll(newPurchases);
      });
    });
  }

  // Returns purchase of specific product ID
  PurchaseDetails? _hasPurchased(List<String> productIDs) {
    try {
      return _purchases
          .firstWhere((purchase) => productIDs.contains(purchase.productID));
    } catch (e) {
      return null;
    }
  }

  // Your own business logic to setup a consumable
  void _verifyPurchase() {
    PurchaseDetails? purchase = _hasPurchased(_productIDs);

    if (purchase != null && purchase.status == PurchaseStatus.purchased) {
      updateSubscriptionTypeData(_users, purchase.productID);
    } else {
      updateSubscriptionTypeData(_users, '');
    }
  }

  // Purchase a product
  void _buyProduct(ProductDetails prod) {
    final PurchaseParam purchaseParam = PurchaseParam(productDetails: prod);
    _iap.buyNonConsumable(purchaseParam: purchaseParam); // For subscriptions
  }

相关问题报告

3   StoreKit                            0x7ff8175f6c7d -[SKPaymentQueue finishTransaction:] + 361
4   in_app_purchase_storekit               0x10eacdd5d -[FIAPaymentQueueHandler finishTransaction:] + 93 (FIAPaymentQueueHandler.m:151)
5   in_app_purchase_storekit               0x10eadfd83 InAppPurchasePlugin.finishTransactionFinishMap(_:error:) + 2659 (InAppPurchasePlugin.swift:248)
6   in_app_purchase_storekit               0x10eae00a2 @objc InAppPurchasePlugin.finishTransactionFinishMap(_:error:) + 98
7   in_app_purchase_storekit               0x10ead9926 __SetUpInAppPurchaseAPI_block_invoke.456 + 150 (messages.g.m:705)
flutter flutter-in-app-purchase
1个回答
0
投票

我解决了这个问题:

  1. 更新
    in_app_purchase
  2. 跑步
    flutter clean
  3. 跑步
    flutter build ios --release --no-tree-shake-icons
© www.soinside.com 2019 - 2024. All rights reserved.