应用商店应用UWP 应用的许可证状态"Inactive license"



以下是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;
}

}

我困惑的是,当应用程序检测到";非活动许可证"?

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

欢迎发表评论

如果当前应用程序许可证无效,则可以使用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;
}
}

最新更新