【发布时间】:2021-06-19 20:13:55
【问题描述】:
我想检查用户是否购买了去除广告的非消耗品。
所以当应用程序启动时(启动活动),我在下面运行代码。
@override
void initState() {
_checkPurchasedItem();
super.initState();
}
_checkPurchasedItem() async {
_preferences = await SharedPreferences.getInstance();
InAppPurchaseConnection _iap = InAppPurchaseConnection.instance;
final QueryPurchaseDetailsResponse response = await _iap.queryPastPurchases();
if(response.error != null) {
debugPrint("splash: check purchased item error");
debugPrint("error: " + response.error.message);
debugPrint("error: " + response.error.code);
debugPrint("error: " + response.error.details.toString());
return;
}
for (PurchaseDetails details in response.pastPurchases) {
if (details.productID == nonConsumableID || details.productID == IOSNonConsumableID) {
_preferences.setBool("removeAd", true);
debugPrint("splash: remove ad");
} else {
_preferences.setBool("removeAd", false);
debugPrint("splash: not remove ad");
}
}
}
但是,在if(response.error != null) 中确实有错误。
消息是BillingResponse.serviceDisconnected。
代码是restore_transactions_failed。
详细信息是null。
为什么iap.quertPastPurchases() 返回错误?
是否有任何正确的方法可以检查用户是否购买了产品?
【问题讨论】:
-
有解决办法吗?