【问题标题】:StoreAppLicense status "Inactive license" of UWP appUWP 应用的 StoreAppLicense 状态“非活动许可证”
【发布时间】:2020-11-04 11:27:37
【问题描述】:

以下是 UWP 应用在用户 PC 上获取许可证信息的代码

 private static async Task<int> getLicenseState()
    {
        StoreAppLicense license = await appStoreContext.GetAppLicenseAsync();
        //string licenseMode;
         
        if (license.IsActive)
        {
            if (license.IsTrial)
            {
                //licenseMode = "Trial license";
                return 0;
            }
            else
            {
                //licenseMode = "Full license";
                return 1; 
            }
        }
        else
        {
            //licenseMode = "Inactive license";
            return 2;
        }
         
    }

我困惑的是当应用程序检测到“无效许可证”时如何处理它?

停止应用程序?或者只是显示一些警告信息?还是触发一个窗口要求用户购买应用?

欢迎评论

【问题讨论】:

    标签: uwp


    【解决方案1】:

    如果当前应用授权无效,可以使用StoreContext.RequestPurchaseAsync提醒用户购买应用。

    private StoreContext context = null;
    
    public async void PurchaseAddOn(string storeId)
    {
        if (context == null)
        {
            context = StoreContext.GetDefault();
            // If your app is a desktop app that uses the Desktop Bridge, you
            // may need additional code to configure the StoreContext object.
            // For more info, see https://aka.ms/storecontext-for-desktop.
        }
    
        workingProgressRing.IsActive = true;
        StorePurchaseResult result = await context.RequestPurchaseAsync(storeId);
        workingProgressRing.IsActive = false;
    
        // Capture the error message for the operation, if any.
        string extendedError = string.Empty;
        if (result.ExtendedError != null)
        {
            extendedError = result.ExtendedError.Message;
        }
    
        switch (result.Status)
        {
            case StorePurchaseStatus.AlreadyPurchased:
                textBlock.Text = "The user has already purchased the product.";
                break;
    
            case StorePurchaseStatus.Succeeded:
                textBlock.Text = "The purchase was successful.";
                break;
    
            case StorePurchaseStatus.NotPurchased:
                textBlock.Text = "The purchase did not complete. " +
                    "The user may have cancelled the purchase. ExtendedError: " + extendedError;
                break;
    
            case StorePurchaseStatus.NetworkError:
                textBlock.Text = "The purchase was unsuccessful due to a network error. " +
                    "ExtendedError: " + extendedError;
                break;
    
            case StorePurchaseStatus.ServerError:
                textBlock.Text = "The purchase was unsuccessful due to a server error. " +
                    "ExtendedError: " + extendedError;
                break;
    
            default:
                textBlock.Text = "The purchase was unsuccessful due to an unknown error. " +
                    "ExtendedError: " + extendedError;
                break;
        }
    }
    

    【讨论】:

    • 'Inactive license' 是否意味着当前的应用程序许可证过期
    • 您好,您可以使用StoreAppLicense.ExpirationDate判断license是否过期。为了避免误解,我已经修改了答案中的相关描述。根据document中的描述,当StoreAppLicense.IsActiveFalse时,表示许可证无效,用户可能需要购买应用程序。
    • 这个 (StoreAppLicense.IsActive) 可以用来检测应用程序的侧载盗版实例吗?
    猜你喜欢
    • 2019-11-11
    • 2018-08-24
    • 1970-01-01
    • 2019-08-02
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多