【问题标题】:Check if renewable subscription is active with Xamarin.Forms (Plugin.InAppBilling)使用 Xamarin.Forms (Plugin.InAppBilling) 检查可更新订阅是否处于活动状态
【发布时间】:2020-09-07 12:08:40
【问题描述】:

我有一个带有一些可更新订阅的 Xamarin.Forms 应用程序。我正在使用InAppBilling plugin 购买这些订阅。现在我的问题是:(我已经在this post 中问过)如何检查可更新订阅是否有效?提前致谢。

【问题讨论】:

    标签: xamarin.forms in-app-billing subscription in-app-subscription auto-renewing


    【解决方案1】:

    通过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();
        }
    

    【讨论】:

    • 感谢您的回答,非常感谢。所以我的问题是,我不知道如何检查用户是否已经订阅了可更新订阅。我试过这个: var purchase = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.Subscription);但这会返回任何购买,即使它已过期。
    • 我以前没有使用过这个插件,我假设如果用户没有订阅可更新订阅,当你调用 PurchaseAsync 时你会得到 null。 illing.ConnectAsync 是否可以检查订阅?
    • 如果我再次购买订阅,它会返回 null,但每次应用程序检查订阅时,都会显示此消息:you have already subscribed to this article。并且billing.ConnectAsync 将设备连接到计费服务。
    • 好吧,你可以在这个插件的 Github 中打开一个 issue 以获得更多帮助。
    • 是的,如果你找到任何解决方案,你可以在这里分享。
    猜你喜欢
    • 1970-01-01
    • 2020-01-11
    • 2019-12-10
    • 1970-01-01
    • 2012-06-02
    • 2014-05-24
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多