StoreLicense类中的IsActive是否可用?

问题描述 投票:1回答:1

只是想知道是否有人可以帮助我。

我实现了以下代码来检查用户是否为我的UWP应用程序购买了一个针对Creator更新的插件:

foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)
{
    StoreLicense addOnLicense = item.Value;

    if (addOnLicense.IsActive)
    {
         Frame.Navigate(typeof(thispage));
    }

    else
    {
         var messageDialog = new MessageDialog("You need to buy the add-on to access this part of the app.");
         await messageDialog.ShowAsync();
    }
}

但是,IsActive似乎总是回归真实。在Microsoft文档上进行研究时,在StoreLicense类中,我发现IsActive属性“保留供将来使用,并且不打算在当前版本中使用。目前,它总是返回true。”因此,如果是这种情况,我如何确定用户是否拥有加载项的活动许可证?

任何帮助将非常感激。

干杯

c# uwp in-app-purchase add-on
1个回答
1
投票

显然,没有必要检查IsActive属性的值以查看附加许可证是否有效,因为AddOnLicenses字典仅包含用户具有活动许可证的产品:

备注

此集合包含当前有效的持久附加许可证。许可证过期或不再有效时,此集合中将不再提供此许可证。 [AddOnLicenses property of StoreAppLicense class]

因此,只需检查加载项是否在集合中就可以完成工作。

或者,您可以检查IsActive类的ProductLicense属性的值(使用较旧的Windows.ApplicationModel.Store命名空间):

private bool IsLicenseActive(string productName)
{
    return CurrentApp.LicenseInformation.ProductLicenses[productName].IsActive);
}

请注意,如果互联网连接不良,执行此方法可能需要一段时间,因此最好将其包装在Task中并异步等待结果以避免冻结UI。

© www.soinside.com 2019 - 2024. All rights reserved.