0

我是否需要缓存拥有应用内购买许可证的事实?例如,用户可能没有互联网连接。我不想使用该方法在每个应用程序启动时检查许可证。

await CurrentApp.LoadListingInformationAsync();

是否需要在独立存储中缓存应用内购买?例如:

    /// <summary>
    /// Get list of In-app purchased
    /// </summary>
    /// <returns></returns>
    public async Task<List<string>> GetOwnedItems()
    {
        var settings = IsolatedStorageSettings.ApplicationSettings;

        List<string> items = (List<string>)settings["PurchasedProducts"];

        if (!items.Any()) //TODO If no purchases, call this block one time, no more!!!
        {
            ListingInformation li = await CurrentApp.LoadListingInformationAsync();
            items = new List<string>();

            foreach (string key in li.ProductListings.Keys)
            {
                if (CurrentApp.LicenseInformation.ProductLicenses[key].IsActive)
                    items.Add(key);
            }

           //Save to IsolatedStorage
           settings["PurchasedProducts"] = items;
        }

        return items;
    }

    public async void PurcaseItem(string itemKey)
    {
        if (!Store.CurrentApp.LicenseInformation.ProductLicenses[itemKey].IsActive)
        {
            ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();
            string pID = li.ProductListings[itemKey].ProductId;

            string receipt = await Store.CurrentApp.RequestProductPurchaseAsync(pID, false);

            var settings = IsolatedStorageSettings.ApplicationSettings;

            //TODO Add key to Isolated storage
            List<string> items = ((List<string>)settings["PurchasedProducts"]).Add(pID);

        }
    }
4

1 回答 1

1

不,无需缓存应用内购买。Windows Phone 操作系统在LicenseInformation 类中为您执行此操作。

如果没有 Internet 连接,用户也无法进行任何应用内购买。因此,您不必担心丢失用户许可证。

于 2013-10-14T11:57:24.603 回答