StoreProduct IsInUserCollection始终为false

时间:2018-06-25 12:10:58

标签: windows-store-apps windows-store

我们在Microsoft Store中提供了UWP产品。该产品具有许多订阅附件。用户进行应用内购买订阅附件。 编辑我们的代码来自Microsoft文档Enable subscription add-ons for your app

StorePurchaseResult result = await product.RequestPurchaseAsync();
if (result.Status == StorePurchaseStatus.Succeeded)

结果返回StorePurchaseStatus.Succeeded。 Microsoft已从用户的钱中购买了订阅附件。到目前为止一切都很好。

我们选择这样的产品列表

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

StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(filterList);
productList = queryResult.Products.Values.ToList();

然后遍历

foreach (StoreProduct storeProduct in products)
{
    if (storeProduct.IsInUserCollection)
...
}

但是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提供的代码示例可以按预期工作。

1 个答案:

答案 0 :(得分:1)

我不确定您为什么要使用该方法。我目前在我的应用程序中执行此操作的方式以及Microsoft文档所建议的方式如下...

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;
}