アプリ内購入のライセンスを持っているという事実をキャッシュする必要がありますか? たとえば、ユーザーがインターネットに接続していない可能性があります。という方法で、アプリケーション起動ごとにライセンスを確認したくありません。
await CurrentApp.LoadListingInformationAsync();
アプリ内購入を IsolatedStorage にキャッシュする必要はありますか? 例えば:
/// <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);
}
}