josuegomes
josuegomes

Reputation: 501

StoreContext.GetAppLicenseAsync returns no cached license when device is offline

This is a classic Win32 application distributed on MS Store.

At startup, it checks the status of the product license. See excerpt below (C++/WinRT):

#include <Windows.Foundation.h>
#include <Windows.System.h>
#include <Windows.Services.Store.h>

enum class LicenseStatus
{
    none,
    error,

    valid,
};

void Init()
{
    winrt::init_apartment();
}

LicenseStatus GetAppLicenseStatus()
{
    using namespace winrt::Windows::Services::Store;

    try {
        if (auto storeContext = StoreContext::GetDefault()) {
            if (auto storeProductRes = storeContext.GetStoreProductForCurrentAppAsync().get()) {
                if (auto storeProduct = storeProductRes.Product()) {
                    //auto storeId = storeProduct.StoreId();
                    if (auto appLicense = storeContext.GetAppLicenseAsync().get()) {
                        if (appLicense.IsActive()) {
                            return LicenseStatus::valid;
                        }
                    }
                }
            }
        }
    }
    catch (winrt::hresult_error const& ex) {
        return LicenseStatus::error;
    }
    catch (std::exception const& ex) {
        return LicenseStatus::error;
    }
}

When the device is offline GetAppLicenseAsync returns immediately. And the call to IsActive returns false. Previously, while online, it returned true.

Documentation [1]: "If this method is called while the device is offline, it returns the cached value of the current licenses on the device."

[1] https://learn.microsoft.com/en-us/uwp/api/windows.services.store.storecontext.getapplicenseasync?view=winrt-22621

Upvotes: 0

Views: 92

Answers (0)

Related Questions