Windows store apps StoreProduct IsInUserCollection始终为false

Windows store apps StoreProduct IsInUserCollection始终为false,windows-store-apps,windows-store,Windows Store Apps,Windows Store,我们在微软商店有一个UWP产品。该产品有许多订阅附加组件。用户在应用程序内购买订阅加载项。 编辑我们的代码是从Microsoft文档中拼凑而成的 结果返回StorePurchaseStatus.successed。微软已经收取了用户的订阅附加组件费用。到目前为止一切都很好 我们有这样的产品清单 string[] productKinds = { "Durable" }; List<String> filterList = new List<string>(productK

我们在微软商店有一个UWP产品。该产品有许多订阅附加组件。用户在应用程序内购买订阅加载项。 编辑我们的代码是从Microsoft文档中拼凑而成的

结果返回
StorePurchaseStatus.successed
。微软已经收取了用户的订阅附加组件费用。到目前为止一切都很好

我们有这样的产品清单

string[] productKinds = { "Durable" };
List<String> filterList = new List<string>(productKinds);

StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList);
productList = queryResult.Products.Values.ToList();
但是
storeProduct.IsInUserCollection
总是返回false。Microsoft已接受该附加组件的付款,但未将其添加到用户的产品集合中,因此我们无法验证他们是否已为该附加组件付款

我们哪里出错了

编辑2根据@lukeja的建议,我运行了这个方法

async Task CheckSubsAsync()
{
    StoreContext context = context = StoreContext.GetDefault();
    StoreAppLicense appLicense = await context.GetAppLicenseAsync();

    foreach (var addOnLicense in appLicense.AddOnLicenses)
    {
        StoreLicense license = addOnLicense.Value;
        Debug.WriteLine($"license.SkuStoreId {license.SkuStoreId}");
    }
}
这只输出一个附加组件。免费的附加组件。我们有16个附加组件,其中只有一个是免费的

为什么我们的付费加载项订阅没有返回


编辑3
appLicense.AddOnLicenses
仅包括当前用户的附加许可证,而不是应用程序的所有附加许可证。@lukeja提供的代码示例在支付订阅费的用户的上下文中运行时,效果与预期一致。

我不确定您为什么要使用该方法。我目前在我的应用程序中做这件事的方式和微软的文档建议的方式是这样的

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.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.IsActive)
{
//在license.ExpirationDate属性中提供了到期日期。
返回true;
}
}
//客户没有订阅的许可证。
返回false;
}

感谢您的回复@lukeja我编辑了我的问题,以显示我从中获取我们使用的代码的Microsoft文档的参考。我们有16个附加组件,当前使用的代码返回我们迭代的所有16个附加组件。您提供的代码仅返回商店中此应用程序的16个加载项中的一个加载项。
async Task CheckSubsAsync()
{
    StoreContext context = context = StoreContext.GetDefault();
    StoreAppLicense appLicense = await context.GetAppLicenseAsync();

    foreach (var addOnLicense in appLicense.AddOnLicenses)
    {
        StoreLicense license = addOnLicense.Value;
        Debug.WriteLine($"license.SkuStoreId {license.SkuStoreId}");
    }
}
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.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;
}