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