2014-05-22 301 views
0

我triyng爲我的應用程序添加應用內購買選項。 我可以正確購買產品,但當我購買並導航到其他頁面並返回購買頁面時,我仍可以再次購買同一產品。當我購買另一種產品時,我購買的舊產品變得沒有購買。應用程序內購買 - 應用程序讓我購買後再次購買

這裏是我的代碼:

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; 
    Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; 

    LicenseChangedEventHandler licenseChangeHandler = null; 


    public SatinAlma() 
    { 
     this.InitializeComponent(); 

    } 


    private async Task LoadInAppPurchaseProxyFileAsync() 
    { 

     StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data"); 
     StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml"); 
     licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario); 
     CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler; 
     await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); 

     try 
     { 
      ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); 

      var PurchasePzl9 = listing.ProductListings["puzzle9"]; 
      var PurchasePzl16 = listing.ProductListings["puzzle16"]; 
      var PurchasePzl25 = listing.ProductListings["puzzle25"]; 
      var PurchaseYardimseverlik = listing.ProductListings["yardimseverlik"]; 
      var PurchaseTumpaket = listing.ProductListings["tumpaket"]; 

     } 
     catch (Exception) 
     { 
      OAL_toast.showToast("LoadListingInformationAsync API call failed\n"); 
     } 
    } 

    ///////**i insert and delete this part nothing changed 
    //protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) 
    //{ 
    // if (licenseChangeHandler != null) 
    // { 
    //  CurrentAppSimulator.LicenseInformation.LicenseChanged -= licenseChangeHandler; 
    // } 
    // base.OnNavigatingFrom(e); 
    //} 
    protected override async void OnNavigatedTo(NavigationEventArgs e) 
    { 
     await LoadInAppPurchaseProxyFileAsync(); 
    } 

    private void InAppPurchaseRefreshScenario() 
    { 

    } 

    private async void purchaseProduct() 
    { 
     LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation; 
     if (!licenseInformation.ProductLicenses[stringPurchaseProduct].IsActive) 
     { 
      try 
      { 
       await CurrentAppSimulator.RequestProductPurchaseAsync(stringPurchaseProduct); 
       if (licenseInformation.ProductLicenses[stringPurchaseProduct].IsActive) 
       { 
        OAL_toast.showToast(stringPurchaseProduct + " purchased."); 
        this.Frame.Navigate(typeof(MainPage)); 
       } 
       else 
       { 
        //OptimeAnimationLib.MsgBox(stringPurchaseProduct + " was not purchased."); 
        OAL_toast.showToast(stringPurchaseProduct + " was not purchased."); 

       } 
      } 
      catch (Exception) 
      { 
       OAL_toast.showToast("Unable to buy " + stringPurchaseProduct); 

      } 
     } 
     else 
     { 
      OAL_toast.showToast("you already own " + stringPurchaseProduct); 

     } 
    } 

    private void IMG_puzzle9_PointerReleased(object sender, PointerRoutedEventArgs e) 
    { 
     LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation; 
     var productLicense = licenseInformation.ProductLicenses["puzzle9"]; 
     if (productLicense.IsActive) 
     { 
      OAL_toast.showToast("you already own Puzzle 9."); 
     } 
     else 
     { 
      stringPurchaseProduct = "puzzle9"; 
      purchaseProduct(); 
     } 

    } 

謝謝,對不起,我的英語

回答

1

它看起來像你重裝每次瀏覽時間您的商店的模擬器的XML文件,這將重置任何商店活動你以前做過。更改代碼,以便只在應用程序啓動時加載XML,然後您應該看到Store狀態在導航中保持自身。還要注意,當你重新啓動應用程序時,你將重新加載XML並重置狀態。

+0

感謝它的工作,其實我認爲,但我不知道爲什麼沒有處理這:)我檢查isxmloaded,如果加載之前不再加載。你能告訴我是我的代碼看起來健康,謝謝:) –