C# 如何在UWP中验证用户脱机时是否购买了订阅?

C# 如何在UWP中验证用户脱机时是否购买了订阅?,c#,uwp,C#,Uwp,如何实现订阅检查。但它并没有提到这是否可以脱机工作。如果它不起作用,那么当用户没有internet连接时,如何验证用户是否购买了订阅? 我认为这个场景无法测试,因为测试场景将返回一个示例响应,它不会查询实际的服务器 private async Task<bool> CheckIfUserHasSubscriptionAsync() { StoreAppLicense appLicense = await context.GetAppLicenseAsync(); /

如何实现订阅检查。但它并没有提到这是否可以脱机工作。如果它不起作用,那么当用户没有internet连接时,如何验证用户是否购买了订阅? 我认为这个场景无法测试,因为测试场景将返回一个示例响应,它不会查询实际的服务器

private async Task<bool> CheckIfUserHasSubscriptionAsync()
{
    StoreAppLicense appLicense = await context.GetAppLicenseAsync();

    // Check if the customer has the rights to the subscription.
    foreach (var addOnLicense in appLicense.AddOnLicenses)
    {
        StoreLicense license = addOnLicense.Value;
        if (license.SkuStoreId.StartsWith(subscriptionStoreId))
        {
            if (license.IsActive)
            {
                // The expiration date is available in the license.ExpirationDate property.
                return true;
            }
        }
    }

    // The customer does not have a license to the subscription.
    return false;
}
专用异步任务checkIfUserHassSubscriptionAsync()
{
StoreAppLicense appLicense=await context.GetAppLicenseAsync();
//检查客户是否拥有订阅的权限。
foreach(appLicense.AddOnLicenses中的var addOnLicense)
{
StoreLicense=addOnlLicense.Value;
if(license.SkuStoreId.StartsWith(subscriptionStoreId))
{
if(license.IsActive)
{
//在license.ExpirationDate属性中提供了到期日期。
返回true;
}
}
}
//客户没有订阅的许可证。
返回false;
}
此方法()返回的对象提供对附加组件的
许可证的访问
和其他信息,例如许可证是否处于活动状态如果在设备脱机时调用此方法,它将返回设备上当前许可证的缓存值。