2014-05-22 358 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,如果加载之前不再加载。你能告诉我是我的代码看起来健康,谢谢:) –