问题
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