Flutter未找到任何应​​用内购买产品

Bis*_*ret 11 android flutter

我正在尝试在我的应用中设置付费产品。

我遵循了Flutter_Inapp_Purchase插件的所有指南,他们都说:

List<IAPItem> items = await FlutterInappPurchase.getProducts([iapId]);
Run Code Online (Sandbox Code Playgroud)

其中iapId是“我的应用的ID”。与该实现有关的所有其他代码均能正常工作,因为当我将android.test.purchased用作iapId字符串时,就可以找到测试产品并将其完美地加载到应用中。因此,问题可能是我正在使用的字符串,因为在任何地方都没有给出其他解释或示例。

我的商店里有一种产品叫remove_ads

那我在iapId这里用错了吗?我无法想象它还会要求什么。

编辑:

购买物品。

我已经更新了以下代码,因为它已经有错误。现在,它在以下几行失败:_verifyPurchase和_deliverPurchase,因为这些不是问题。官方文档似乎说:“您可以继续并从这里开始处理所有这些工作”,甚至没有指示如何开始。

  Future<Null> _queryPastPurchases() async {
    final QueryPurchaseDetailsResponse response = await InAppPurchaseConnection.instance.queryPastPurchases();
    if (response.error != null) {
      // Handle the error.
    }
    for (PurchaseDetails purchase in response.pastPurchases) {
      _verifyPurchase(purchase);  // Verify the purchase following the best practices for each storefront.
      _deliverPurchase(purchase); // Deliver the purchase to the user in your app.
      if (Platform.isIOS) {
        // Mark that you've delivered the purchase. Only the App Store requires
        // this final confirmation.
        InAppPurchaseConnection.instance.completePurchase(purchase);
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

小智 8

我有同样的问题(特定于IOS)。就我而言,要接收 Apple 产品,我需要填写协议、税务和银行表格 ( https://appstoreconnect.apple.com/agreements/ )。填写表格并获得批准后退回产品。


cre*_*not 7

这个答案有点建议,但是,它应该带您实现目标。

颤振团队已经完成了最近的官方插件应用内购买。它是in_app_purchase插件

  1. 我假设您已经阅读了Android开发者指南,以配置您的remove_ads购买。

  2. 您需要in_app_purchasepubspec.yaml文件中添加依赖项:

dependencies:
  in_app_purchase: ^0.2.0 # For newer versions, check the Pub page.
Run Code Online (Sandbox Code Playgroud)
  1. 在Flutter应用中,您现在需要导入'package:in_app_purchase/in_app_purchase.dart'
dependencies:
  in_app_purchase: ^0.2.0 # For newer versions, check the Pub page.
Run Code Online (Sandbox Code Playgroud)
  1. 加载您的产品,您可以使用以下代码:
import 'package:in_app_purchase/in_app_purchase.dart';
Run Code Online (Sandbox Code Playgroud)

有关更多信息和说明,请阅读插件的README并签出示例应用程序

  1. 您需要按照示例README中说明的步骤进行操作。您将需要创建一个remove_adsSKU ID而不是它们提及的内容,因为它们的SKU ID仅适用于示例。


小智 7

您需要使用预留的 SKU 进行测试:android.test.purchased

使用 in_app_purchase 时:

const List<String> _kProductIds = <String>[
  'android.test.purchased'
];
ProductDetailsResponse productDetailResponse =
  await _connection.queryProductDetails(_kProductIds.toSet());
Run Code Online (Sandbox Code Playgroud)


jea*_*dam 6

我在使用 flutter 插件 in_app_purchase 时遇到了同样的问题(notFoundIds )。所以要保证两点:

  1. 确保productId按照插件自述文件的指定在PlayStore/AppStore中注册;

  2. 在调用 queryProductDetails 之前,调用isAppPurchaseAvailable,它将初始化并等待一段时间,直到准备好,然后 queryProductDetails 才会工作。示例代码如下:

       Future<List<ProductDetails>> loadProductsForSale() async {
         if(await isAppPurchaseAvailable()) {
           const Set<String> _kIds = {APP_PRODUCTID01};
           final ProductDetailsResponse response =
           await InAppPurchaseConnection.instance.queryProductDetails(_kIds);
           if (response.notFoundIDs.isNotEmpty) {
             debugPrint(
                 '#PurchaseService.loadProductsForSale() notFoundIDs: ${response
                     .notFoundIDs}');
           }
           if (response.error != null) {
             debugPrint(
                 '#PurchaseService.loadProductsForSale() error: ${response.error
                     .code + ' - ' + response.error.message}');
           }
           List<ProductDetails> products = response.productDetails;
           return products;
         } else{
           debugPrint('#PurchaseService.loadProductsForSale() store not available');
           return null;
         }
       }
    
     Future<bool> isAppPurchaseAvailable() async {
     final bool available = await InAppPurchaseConnection.instance.isAvailable();
    
     debugPrint('#PurchaseService.isAppPurchaseAvailable() => $available');
    
     return available;
     if (!available) {
       // The store cannot be reached or accessed. Update the UI accordingly.
    
       return false;
     }
     }
    
    Run Code Online (Sandbox Code Playgroud)