Windows phone 8 我是否需要在Windows Phone 8中缓存应用内购买?
我是否需要缓存拥有应用内购买许可证的事实?例如,用户可能没有互联网连接。我不想在每次应用程序启动时使用该方法检查许可证Windows phone 8 我是否需要在Windows Phone 8中缓存应用内购买?,windows-phone-8,in-app-purchase,windows-phone,Windows Phone 8,In App Purchase,Windows Phone,我是否需要缓存拥有应用内购买许可证的事实?例如,用户可能没有互联网连接。我不想在每次应用程序启动时使用该方法检查许可证 await CurrentApp.LoadListingInformationAsync(); 是否需要在IsolatedStorage中缓存应用内购买?例如: /// <summary> /// Get list of In-app purchased /// </summary> /// <returns>
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);
}
}
//
///获取已购买的应用程序内的列表
///
///
公共异步任务GetOwnedItems()
{
var设置=隔离存储设置。应用设置;
列表项=(列表)设置[“PurchasedProducts”];
if(!items.Any())//TODO如果没有购买,请调用此块一次,不再调用!!!
{
ListingInformation li=等待CurrentApp.LoadListingInformation同步();
项目=新列表();
foreach(li.ProductListings.Keys中的字符串键)
{
if(CurrentApp.LicenseInformation.ProductLicenses[key].IsActive)
项目。添加(键);
}
//保存到隔离存储
设置[“PurchasedProducts”]=项目;
}
退货项目;
}
公共异步void PurcaseItem(字符串itemKey)
{
如果(!Store.CurrentApp.LicenseInformation.ProductLicenses[itemKey].IsActive)
{
ListingInformation li=wait Store.CurrentApp.LoadListingInformation同步();
字符串pID=li.ProductListings[itemKey].ProductId;
string receive=wait Store.CurrentApp.RequestProductPurchaseAsync(pID,false);
var设置=隔离存储设置。应用设置;
//TODO向独立存储添加密钥
列表项=((列表)设置[“PurchasedProducts”])。添加(pID);
}
}
否,无需缓存应用内购买。
Windows Phone操作系统可以在中为您实现这一点
如果没有互联网连接,用户也无法进行任何应用内购买。因此,您不必担心用户许可证的丢失