问题描述
我尝试了各种技术,但是即使用户,也无法弄清楚为什么此代码总是会导致有效(有效?)许可证。还没有购买该应用程序附件。
该功能在应用启动时初始化。
public async void GetLicenseInfo()
{
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;
StoreAppLicense appLicense = await context.GetAppLicenseAsync();
workingProgressRing.IsActive = false;
if (appLicense == null)
{
messagetextblock.Text = "An error occurred while retrieving the license.";
return;
}
// Use members of the appLicense object to access license info...
// the customer can' t access this feature
messagetextblock.Text = "customer hasn't bought the addon";
// Access the valid licenses for durable add-ons for this app.
foreach (keyvaluePair<string,StoreLicense> item in appLicense.AddOnLicenses)
{
StoreLicense addOnLicense = item.Value;
// Use members of the addOnLicense object to access license info
// for the add-on.
// Specify the kinds of add-ons to retrieve.
string[] productKinds = { "Durable","Consumable","UnmanagedConsumable" };
List<String> filterList = new List<string>(productKinds);
StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(filterList);
if (addOnLicense.IsActive)
{
// the customer can access this feature
messagetextblock.Text = "customer has bought the addon";
}
}
}
解决方法
很难确切地说明上述示例出了什么问题。但是,我在市场上有一个使用两种不同类型的应用程序内购买的应用程序。一个删除广告,另一个获得高级许可。
您执行操作与执行操作之间的区别是,我正在随许可证一起返回的许可证书中查找订阅商店ID。
您尝试过这种方法吗?
public static void CheckForPremiumStatus()
{
#if DEBUG
if (LicenseInformation.ProductLicenses["PremiumStatus"].IsActive)
{
IsPremium = RemoveAds = true;
}
#else
var subscriptionStoreId = "9PMT47KC5W6C";
foreach (var addOnLicense in _appLicense.AddOnLicenses)
{
StoreLicense license = addOnLicense.Value;
if (license.SkuStoreId.StartsWith(subscriptionStoreId))
{
if (license.IsActive)
{
IsPremium = RemoveAds = true;
return;
}
else
{
break;
}
}
}
IsPremium = RemoveAds = false;
#endif
}
You can see the full example here-随时复制并粘贴。只需换出插件商店ID即可