Windows Phone 8.1 and CurrentAppSimulator

I'm trying to add app purchases to my universal app, and I have problems testing it in the Windows Phone version. The manual says that to use CurrentAppSimulator I have to "configure a file called "WindowsStoreProxy.xml" in %userprofile%\AppData\local\packages\<package name>\LocalState\Microsoft\Windows Store\ApiData ".

I cannot do this over the phone because I do not have access to the file system of the phone. How to enable CurrentAppSimulator ?

+5
source share
3 answers
  • Valid for Windows Phone 8.1, Dev Studio 2013

You can access isolated storage files using the "ISETool" located here: "Program Files (x86) \ Microsoft SDK \ Windows Phone \ v8.0 \ Tools \ IsolatedStorageExplorerTool". How to use the isolated storage tool for Windows Phone 8 . After copying them to a folder on your computer, you will have a subfolder of "IsolatedStore". Inside "\ Microsoft \ Windows Store \ ApiData" you will find "WindowsStoreProxy.xml":

 <?xml version="1.0" encoding="utf-16" ?> <CurrentApp> <ListingInformation> <App> <AppId>00000000-0000-0000-0000-000000000000</AppId> <LinkUri>http://apps.microsoft.com/webpdp/app/00000000-0000-0000-0000-000000000000</LinkUri> <CurrentMarket>en-US</CurrentMarket> <AgeRating>3</AgeRating> <MarketData xml:lang="en-us"> <Name>AppName</Name> <Description>AppDescription</Description> <Price>1.00</Price> <CurrencySymbol>$</CurrencySymbol> <CurrencyCode>USD</CurrencyCode> </MarketData> </App> <Product ProductId="1" LicenseDuration="0" ProductType="Durable"> <MarketData xml:lang="en-us"> <Name>Product1Name</Name> <Price>1.00</Price> <CurrencySymbol>$</CurrencySymbol> <CurrencyCode>USD</CurrencyCode> </MarketData> </Product> <Product ProductId="2" LicenseDuration="0" ProductType="Consumable"> <MarketData xml:lang="en-us"> <Name>Product2Name</Name> <Price>1.00</Price> <CurrencySymbol>$</CurrencySymbol> <CurrencyCode>USD</CurrencyCode> </MarketData> </Product> </ListingInformation> <LicenseInformation> <App> <IsActive>true</IsActive> <IsTrial>true</IsTrial> </App> <Product ProductId="1"> <IsActive>true</IsActive> </Product> </LicenseInformation> <ConsumableInformation> <Product ProductId="2" TransactionId="00000000-0000-0000-0000-000000000000" Status="Active" /> </ConsumableInformation> 

Copy this file to your resources folder and include it in your project. Modify the file, you need to change ProductId from "1" to "Your Product Identifier". You can remove the product with the product id = "2" if you do not need a consumable product in the application. Change the second license information to:

 <LicenseInformation> <App> <IsActive>true</IsActive> <IsTrial>false</IsTrial> </App> <Product ProductId="Your Product ID"> <IsActive>false</IsActive> </Product> </LicenseInformation> 

Make your application constructor look like this:

 private static LicenseInformation licenseInformation=null; public App() { this.InitializeComponent(); this.Suspending += this.OnSuspending; #if DEBUG licenseInformation = CurrentAppSimulator.LicenseInformation; #else licenseInformation = CurrentApp.LicenseInformation; #endif licenseInformation.LicenseChanged += licenseInformation_LicenseChanged; } 

Add event handler:

 private static void licenseInformation_LicenseChanged() { if (licenseInformation.ProductLicenses["Your Product ID"].IsActive) { // add code for purchased (eg property of a data class derived from INotifyPropertyChanged) } else { // add code for not yet purchased (eg property of a data class derived from INotifyPropertyChanged) } } 

Add something like this to the App class:

 public static async void RequestFeatureXYZ() { if (!licenseInformation.ProductLicenses["Your Product ID"].IsActive) { try { #if DEBUG StorageFolder installFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets"); StorageFile appSimulatorStorageFile = await installFolder.GetFileAsync("WindowsStoreProxy.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(appSimulatorStorageFile); PurchaseResults result = await CurrentAppSimulator.RequestProductPurchaseAsync("Your Product ID"); #else PurchaseResults result = await CurrentApp.RequestProductPurchaseAsync("Your Product ID"); #endif // licenseInformation_LicenseChanged(); // (un)comment if you find out that the event does (not) always fire } catch (Exception ex) { // handle error or do nothing } } } 

And links ..

 using Windows.Storage; using Windows.Storage.Streams; using Windows.ApplicationModel.Store; using System.ComponentModel; 
+9
source

They provided an API for this. You need to use Windows.ApplicationModel.Store.CurrentAppSimulator.ReloadSimulatorAsync(IStorageFile file) and point it to the attached file "WindowsStoreProxy.xml". The structure of this file is identical to the structure that you will use in Windows 8.1.

+1
source

More details in the previous answer:

1.Create the "Data" folder in your solution with the WindowsStoreProxy.xml file (or another name).

2. Set in the properties file "output directory for copying" - "copy new version".

  1. Use this method:

      public static async Task ConfigureSimulatorAsync() { var proxyFile = await Package.Current.InstalledLocation.GetFileAsync(@"data\WindowsStoreProxy.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); } protected override async void OnNavigatedTo(NavigationEventArgs e) { await MainPage.ConfigureSimulatorAsync(); } 
0
source

Source: https://habr.com/ru/post/1201992/


All Articles