locked
In-App Purchase simulator - License information gone after navigate

    Question

  • hi everyone.

    i'm trying to add in-app purchase in my application. but when i navigate to mainpage from purchase page after purchased product and navigate back to purchase page my licenseinfo lost(i think). i can purchase same product again after navigate.  sorry for my english and let me insert my codes here.

    where is my mistake.

    thanks.

    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);
    
    
                // setup application upsell message
                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");
                }
            }
    
    
    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.");
                            OptimeAnimationLib.MsgBox(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";
                    sayilariGoster();
                }
    
            }
    
    
    

    Tuesday, May 20, 2014 11:06 PM

Answers

  • Your OnNavigatedTo method calls LoadInAppPurchaseProxyFileAsync to reload the simulator from scratch each time it gets called. Instead you probably want to load the simulator once for the entire app and then keep that value globally.

    Tuesday, May 20, 2014 11:59 PM
    Owner