使用Xamarin.Forms(Plugin.InAppBilling)检查可再生订阅是否处于活动状态

使用Xamarin.Forms(Plugin.InAppBilling)检查可再生订阅是否处于活动状态,xamarin.forms,in-app-billing,subscription,in-app-subscription,auto-renewing,Xamarin.forms,In App Billing,Subscription,In App Subscription,Auto Renewing,我有一个Xamarin.Forms应用程序,有一些可续费订阅。我正在使用来购买这些订阅。现在我的问题是:(我已经在中问过)我如何检查续费订阅是否有效?提前感谢。通过,您可以通过 var connected=wait billing.ConnectAsync(ItemType.Subscription): 以下是一个例子: public async Task<bool> PurchaseItem(string productId, string payload) { var b

我有一个Xamarin.Forms应用程序,有一些可续费订阅。我正在使用来购买这些订阅。现在我的问题是:(我已经在中问过)我如何检查续费订阅是否有效?提前感谢。

通过,您可以通过

var connected=wait 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();
    }
public异步任务PurchaseItem(字符串productId,字符串有效负载)
{
var计费=CrossInAppBilling.Current;
尝试
{
var connected=wait billing.ConnectAsync(ItemType.InAppPurchase);
如果(!已连接)
{
//我们处于脱机状态或无法连接,请不要尝试购买
返回false;
}
//检查购买情况
var purchase=wait billing.PurchaseAsync(productId,ItemType.InAppPurchase,payload);
//一个空值通过的可能性。
如果(购买==null)
{
//没有购买
}
else if(purchase.State==PurchaseState.Purchased)
{
//购买!
}
}
捕获(在应用BillingPurchaseException purchaseEx中)
{
//计费异常根据类型处理此异常
Debug.WriteLine(“错误:+purchaseEx”);
}
捕获(例外情况除外)
{
//还有什么地方出了问题,记录下来
Debug.WriteLine(“问题连接:+ex”);
}
最后
{
等待计费。DisconnectAsync();
}

谢谢您的回答,我真的很感激。所以我的问题是,我不知道如何检查用户是否已经订阅了可续费订阅。我尝试了以下方法:var purchases=wait crossinappling.Current.GetPurchasesAsync(ItemType.subscription);但这会返回任何购买,如果它已过期也会返回。我以前没有使用此插件,我假设如果用户未订阅可续费订阅,则调用PurchaseAsync时,您将得到null。illing.ConnectAsync是否会检查订阅?如果我再次购买订阅,它将返回null,但每次应用程序检查时都会返回nulls对于订阅,将显示以下消息:
您已经订阅了这篇文章
。和
计费。ConnectAsync
将设备连接到计费服务。您可以在Github中打开此插件的问题以获得更多帮助。是的,如果您找到任何解决方案,可以在此处共享。