【发布时间】:2020-09-07 12:08:40
【问题描述】:
我有一个带有一些可更新订阅的 Xamarin.Forms 应用程序。我正在使用InAppBilling plugin 购买这些订阅。现在我的问题是:(我已经在this post 中问过)如何检查可更新订阅是否有效?提前致谢。
【问题讨论】:
标签: xamarin.forms in-app-billing subscription in-app-subscription auto-renewing
我有一个带有一些可更新订阅的 Xamarin.Forms 应用程序。我正在使用InAppBilling plugin 购买这些订阅。现在我的问题是:(我已经在this post 中问过)如何检查可更新订阅是否有效?提前致谢。
【问题讨论】:
标签: xamarin.forms in-app-billing subscription in-app-subscription auto-renewing
通过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();
}
【讨论】:
you have already subscribed to this article。并且billing.ConnectAsync 将设备连接到计费服务。