0
我是否需要緩存具有應用內購買許可的事實?例如,用戶可能沒有互聯網連接。我不想在每個應用程序啓動時使用該方法檢查許可證。我是否需要緩存Windows Phone 8中的應用內購買?
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);
}
}