Reputation: 151
Just wondering if anyone can help me out.
I implemented the following piece of code to check if the user has bought an add-on for my UWP app targeting the Creator's Update:
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();
}
}
However, IsActive always seemed to return true. When researching this on Microsoft docs, in the StoreLicense Class, I found out that the IsActive property is "reserved for future use, and it is not intended to be used in the current release. Currently, it always returns true." So if this is the case, how can I determine if the user has an active license for my add-on?
Any help would be much appreciated.
Cheers
Upvotes: 1
Views: 467
Reputation: 2383
Apparently, there's no need to check the value of IsActive
property to see if the add-on license is valid, since AddOnLicenses
dictionary only contains products for which the user has active license:
Remarks
This collection contains durable add-on licenses that are currently valid. When a license is expired or no longer valid, it will no longer be available in this collection. [
AddOnLicenses
property ofStoreAppLicense
class]
So, simply checking if the add-on is in the collection should do the job.
Alternatively, you can check the value of IsActive
property of the ProductLicense
class (uses older Windows.ApplicationModel.Store
namespace):
private bool IsLicenseActive(string productName)
{
return CurrentApp.LicenseInformation.ProductLicenses[productName].IsActive);
}
Note that execution of this method may take a while in case of bad internet connection, so you're better off wrapping it in Task
and waiting for the result asynchronously to avoid freezing the UI.
Upvotes: 1