为什么queryPastPurchase在iOS Testflight用户上返回null,而在Android上成功返回。
请帮助我解决这个问题。
这是我的代码:
...
InAppPurchaseConnection _iap = InAppPurchaseConnection.instance;
@override
initState() {
_initialize();
super.initState();
}
void _initialize() async {
// Check availability of In App Purchases
_available = await _iap.isAvailable();
if (_available) {
await _getProducts();
await _getPastPurchases();
_getSubscriptionPrice();
}
_subscription = _iap.purchaseUpdatedStream.listen((data) => setState(() {
_purchases.addAll(data);
for(PurchaseDetails purchase in _purchases){
if(purchase.productID == 'subName'){
setState(() {
showSubscriptionDialog = false;
});
}
}
_verifyPurchase();
}));
}
/// Get all products available for sale
Future<void> _getProducts() async {
Set<String> ids = Set.from(['subName']);
ProductDetailsResponse response = await _iap.queryProductDetails(ids);
setState(() {
_products = response.productDetails;
});
if(response.error != null && response.error.message.length > 0){
_iapStoreProblem = response.error.message;
}
}
/// Gets past purchases
Future<void> _getPastPurchases() async {
bool hasSub = false;
QueryPurchaseDetailsResponse response = await _iap.queryPastPurchases();
for (PurchaseDetails purchase in response.pastPurchases) {
if (Platform.isIOS) {
InAppPurchaseConnection.instance.completePurchase(purchase);
}
}
setState(() {
_purchases = response.pastPurchases;
});
for(PurchaseDetails purchase in _purchases){
if(purchase.billingClientPurchase.sku == "subName"){
hasSub = true;
}
}
if(hasSub){
setState(() {
showSubscriptionDialog = false;
firstTimeBuySub = false;
});
}else{
setState(() {
showSubscriptionDialog = true;
firstTimeBuySub = true;
});
}
}
[执行buyProduct()时,它会在_initialize()中找到订阅的购买,仅当我尝试执行_getPastPurchases()时,它无法在iOS上向我返回任何产品。
void _buyProduct(ProductDetails prod) {
final PurchaseParam purchaseParam = PurchaseParam(productDetails: prod, sandboxTesting: true);
_iap.buyNonConsumable(purchaseParam: purchaseParam);
}
我有类似的问题。您解决了这个问题吗?
在我的应用程序中,queryPastPurchases在IOS中返回null,但在Android中的作用与您的问题相同。
因此,如果您解决了此问题,请让我知道如何解决此问题。谢谢。