问题描述
为什么queryPastPurchases()在Android上返回带有我的订阅的填充列表,而在iOS上返回空列表?
Why does queryPastPurchases() return a populated list with my subscription on android, but returns an empty list on iOS?
我有一部物理的iOS SE手机,我的苹果用户被添加为testflight中的测试者,我在App Store Connect中添加了一个订阅,并且能够购买该订阅(在testflight中).但是queryPastPurchases()返回一个空列表...
I have a physical iOS SE phone, my apple user is added as an tester in testflight, I've added a subscription in App Store Connect, and I am able to buy the subscription(in testflight). However queryPastPurchases() returns an empty list...
// Gets past purchases
Future<void> _getPastPurchases() async {
QueryPurchaseDetailsResponse response =
await _iap.queryPastPurchases();
for (PurchaseDetails purchase in response.pastPurchases) {
if (Platform.isIOS) {
InAppPurchaseConnection.instance.completePurchase(purchase);
}
}
setState(() {
_purchases = response.pastPurchases;
});
}
推荐答案
结果证明代码没有错.
为了使其工作,我必须创建一个沙箱用户.然后,我不得不从当前在手机上登录的AppID中注销.然后,我必须在Xcode中从发布到调试使用编辑方案".然后我在终端上运行了"flutter run".然后,我购买了NonConsumable订阅,然后在对话框中,必须输入沙盒用户的电子邮件和密码.
In order to make it work I had to create a sandbox user.Then I had to log out from my current logged in AppID on the phone.Then I had to "Edit Scheme" in Xcode from Release to Debug.Then I ran "flutter run" in terminal.Then I purchased my NonConsumable subscription, and in the dialog I had to enter the sandbox user email and pwd.
已更新:另外,我还必须在App Store Connect中创建一个全新的订阅,因为原始订阅陷入了无法购买或购买的状态.这是由于completePurchase
在我的代码中的错误位置完成的.不应在_getPastPurchases()
中完成此操作,而应在实际的购买逻辑中完成.
Updated:Also I had to create a completely new subscription in app store connect, because the original subscription got trapped in a state were it was not bought nor purchasable. This was due to the fact that the completePurchase
was done at the wrong place in my code.It should not be done in _getPastPurchases()
, but rather in the actual purchase logic.
因此将completePurchase
放在此处:
_subscription = _iap.purchaseUpdatedStream.listen((data) => setState(() {
_purchases.addAll(data);
for(PurchaseDetails purchase in _purchases){
if(purchase.productID == 'subName'){
//SOLUTION
if (Platform.isIOS) {
InAppPurchaseConnection.instance.completePurchase(purchase);
}
}
}
}));
PS:我不记得我是否在for循环中或外部有completePurchse ...
PS: I don't remember if I had the completePurchse in the for loop or outside...
这篇关于Flutter in_app_purchase queryPastPurchases()在iOS上返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!