question

FeiXue-MSFT avatar image
FeiXue-MSFT asked ·

How to check if an add-on has purchased that use StoreContext class

I have defined a durable AddOn, and when I used RequestPurchaseAsync() method to check if an add-on has purchased or not, it always shows UI which will be annoying to the user.

In the previous version I used: CurrentApp.LicenseInformation.ProductLicenses[ProductId].IsActive to check if the add-on has purchased. So is there any method in StoreContext to solve the problem?

windows-uwpwindows-uwp-runtime
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RoyLi-MSFT avatar image
RoyLi-MSFT answered ·

Hello,

Welcome to our Microsoft Q&A platform!

In order to check if an add-on has purchased or not, please check the license information using StoreContext Class. To access the licenses for durable add-ons of the current app for which the user has an entitlement to use, use the AddOnLicenses property of the StoreAppLicense object as follows:

 public async void GetLicenseInfo()
 {
     if (context == null)
     {
         context = StoreContext.GetDefault();
     }
     StoreAppLicense appLicense = await context.GetAppLicenseAsync();
    
     if (appLicense == null)
     {
         textBlock.Text = "An error occurred while retrieving the license.";
         return;
     }
    
     // Access the valid licenses for durable add-ons for this app.
     foreach (KeyValuePair item in appLicense.AddOnLicenses)
     {
         StoreLicense addOnLicense = item.Value;
         // Use members of the addOnLicense object to access license info
         // for the add-on.
     }
 }


For more information, please refer to this document: Get license info for apps and add-ons.

Thanks





Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.