我正在使用Xamarin.InAppBilling component,并且一直遇到错误。问题在于覆盖方法:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
// Ask the open service connection's billing handler to process this request
_serviceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
// Ask the open connection's billing handler to get any purchases
var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
foreach (var purchase in purchases) {
FufillOrder(purchase);
}
}
使用保留ID "android.test.purchased"
时,a reserved product string,此覆盖方法在本地和我的应用程序的实时Beta频道中都可以正常工作。调用该方法,并完成产品。
然而,对于任何实时应用内商品,那些由ID字符串填充的内容:
Products = await _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string> {
"example",
}, ItemType.Product);
当用户完成购买周期时,不会调用此方法。
为了进一步混淆 - 在Android Merchant Console中,订单已成功处理,并报告为“已发送”,因此没有问题。
然而,问题仍然存在。以下代码不适用于实时产品:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) {
// Ask the open service connection's billing handler to process this request
_serviceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
// Ask the open connection's billing handler to get any purchases
var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
foreach (var purchase in purchases) {
FufillOrder(purchase);
}
}
订单未履行或已消耗。有趣的是,我把它扔在_serviceConnection.OnConnected:
var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
foreach (var purchase in purchases) {
_serviceConnection.BillingHandler.ConsumePurchase(purchase);
}
这对于实时产品都不起作用。他们没有消耗。 (尽管如此,它确实适用于android.test.purchased
)。