Flutter in_app_purchase pastPurchases is null in IOS

筅森魡賤 提交于 2020-02-06 08:18:14

问题


I use in_app_purchase Flutter Package.

In my app, app contains auto-renewal subscription. and I need to check user's subscription state. code below, I check user's subscription state. It works in android. but, in IOS, not working.

Future<bool> getHistoryInApp() async {
  BuildContext context;
  available = await _iap.isAvailable();

  if(Platform.isIOS){
    _iap.refreshPurchaseVerificationData();
  }

  QueryPurchaseDetailsResponse response = await _iap.queryPastPurchases();

  Fluttertoast.showToast(msg: 'response.pastPurchases:\n' + response.pastPurchases.toString());
  print(response.pastPurchases);
  if(available) {
    if(response.error != null) {
      // error
      print('error');
      return false;
    }

    for (PurchaseDetails purchase in response.pastPurchases) {
      verifyPurchase(purchase);
      if (Platform.isIOS) {
        InAppPurchaseConnection.instance.completePurchase(purchase);
      }
    }

    purchases = response.pastPurchases;
    if (purchases.length == 0) {
      updateSubscribeYN(context, Mnote.isInApp ? 'Y' : 'N');
      print('inapp purchase 0');
      return false;
    }else {
      print(purchases[0].purchaseID + '\n' + 'productID: ' + purchases[0].productID);
      updateSubscribeYN(context, Mnote.isInApp ? 'Y' : 'N');
      print('inapp purchase purchased');
      return true;
    }
  }else {
    updateSubscribeYN(context, Mnote.isInApp ? 'Y' : 'N');
    print('inapp purchase fail');
    return false;
  }
}

In IOS, available is true but response.pastPurchases is null. so in IOS, I never can check past purchase.

This returns false with print('inapp purchase 0'); in if(purchases.length == 0). because response.pastPurchases is null.

But, In Appstore, My app is in my apple ID's subscribe list after I purchase my item.

I can't understand this issue.. is anyone know about this problem?

(I tested in release. I passed apple's review and I released my app. almost 1 month ago, I tested this app in TestFlight. in TestFlight, check pastPurchases worked and I thought this works correctly. but after release, pastPurchases never works in IOS..)

来源:https://stackoverflow.com/questions/58832779/flutter-in-app-purchase-pastpurchases-is-null-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!