2013-10-12 39 views
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); 

     } 
    } 

回答

1

不,不需要緩存應用內購買。 Windows Phone操作系統在LicenseInformation Class中爲您執行此操作。

如果沒有互聯網連接,用戶也無法執行任何應用內搜索。所以你不必擔心丟失用戶許可證。

相關問題