StoreAppLicense状态“;“非活动许可证”;UWP应用程序的开发

StoreAppLicense状态“;“非活动许可证”;UWP应用程序的开发,uwp,Uwp,下面是UWP应用程序在用户PC上获取许可证信息的代码 private static async Task<int> getLicenseState() { StoreAppLicense license = await appStoreContext.GetAppLicenseAsync(); //string licenseMode; if (license.IsActive) {

下面是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;
        }
         
    }
private静态异步任务getLicenseState()
{
StoreAppLicense许可证=等待appStoreContext.GetApplicenseAync();
//字符串许可模式;
if(license.IsActive)
{
if(license.IsTrial)
{
//licenseMode=“试用许可证”;
返回0;
}
其他的
{
//licenseMode=“完全许可”;
返回1;
}
}
其他的
{
//licenseMode=“非活动许可证”;
返回2;
}
}
我所困惑的是,当应用程序检测到“非活动许可证”时,如何处理它

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


欢迎发表评论

如果当前应用程序许可证无效,则可以使用提醒用户购买该应用程序

private-StoreContext上下文=null;
公共异步void PurchaseAddOn(字符串storeId)
{
if(上下文==null)
{
context=StoreContext.GetDefault();
//如果您的应用程序是使用桌面网桥的桌面应用程序,则
//可能需要其他代码来配置StoreContext对象。
//有关详细信息,请参阅https://aka.ms/storecontext-for-desktop.
}
workingProgressRing.IsActive=true;
StorePurchaseResult=等待上下文。RequestPurchaseAsync(storeId);
workingProgressRing.IsActive=false;
//捕获操作的错误消息(如果有)。
string extendedError=string.Empty;
if(result.ExtendedError!=null)
{
extendedError=result.extendedError.Message;
}
开关(结果状态)
{
case StorePurchaseStatus.AlreadyPurchased:
Text block.Text=“用户已购买该产品。”;
打破
案例StorePurchaseStatus。成功:
Text block.Text=“购买成功。”;
打破
case StorePurchaseStatus.NotPurchased:
textBlock.Text=“购买未完成。”+
用户可能已取消购买。ExtendedError:“+ExtendedError;
打破
case StorePurchaseStatus.NetworkError:
textBlock.Text=“由于网络错误,购买失败。”+
“ExtendedError:”+ExtendedError;
打破
case StorePurchaseStatus.ServerError:
textBlock.Text=“由于服务器错误,购买失败。”+
“ExtendedError:”+ExtendedError;
打破
违约:
textBlock.Text=“由于未知错误,购买失败。”+
“ExtendedError:”+ExtendedError;
打破
}
}

Inactive license(非活动许可证)是否表示当前应用程序许可证到期。如果您想确定许可证是否已到期,可以使用
StoreAppLicense.ExpirationDate
。为了避免误解,我已修改了答案中的相关描述。根据中的描述,当
StoreAppLicense.IsActive
为False时,表示许可证无效,用户可能需要购买该应用程序。此(
StoreAppLicense.IsActive
)是否可用于检测应用程序的旁载盗版实例?