我有一个Xamarin.Forms应用程序,其中包含一些可再生订阅。我正在使用InAppBilling plugin购买这些订阅。现在我的问题是:(我已经在this post中问过)我如何检查可更新订阅是否处于活动状态?预先感谢。
答案 0 :(得分:0)
通过document,您可以通过以下方式查看状态
var connected = await billing.ConnectAsync(ItemType.Subscription);
:
这里是示例:
public async Task<bool> PurchaseItem(string productId, string payload)
{
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
if (!connected)
{
//we are offline or can't connect, don't try to purchase
return false;
}
//check purchases
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, payload);
//possibility that a null came through.
if(purchase == null)
{
//did not purchase
}
else if(purchase.State == PurchaseState.Purchased)
{
//purchased!
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
//Billing Exception handle this based on the type
Debug.WriteLine("Error: " + purchaseEx);
}
catch (Exception ex)
{
//Something else has gone wrong, log it
Debug.WriteLine("Issue connecting: " + ex);
}
finally
{
await billing.DisconnectAsync();
}