Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8.1 and CurrentAppSimulator

I'm trying to add in app purchases to my universal app and am having trouble testing it in the Windows Phone version. The guide says that in order to use the CurrentAppSimulator I must "customize the file named "WindowsStoreProxy.xml" in %userprofile%\AppData\local\packages\<package name>\LocalState\Microsoft\Windows Store\ApiData".

I can't do this on the phone though, as I don't have access to the phone's file system. How do I enable the CurrentAppSimulator?

like image 620
Nate Diamond Avatar asked Sep 07 '14 00:09

Nate Diamond


People also ask

Is Windows Phone 8.1 still supported?

Yes. Your Windows Phone 8.1 device should continue to work after July 11, 2017, but there will be no updates after July 11, 2017 (including security updates) and device backup functionality and other backend services will be phased out as described above.


2 Answers

  • Valid for Windows Phone 8.1, Dev Studio 2013

You can access the isolated storage files using the "ISETool" located here: "Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Tools\IsolatedStorageExplorerTool". How to use the Isolated Storage Explorer tool for Windows Phone 8. After copying them to a folder on your computer you will have a subfolder "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 assets folder and include it in your project. Change the file, you need to change the ProductId from "1" to "Your Product ID". you can remove the product with product id="2" if you don't need a consumable in app product. 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 the constructor of your app look something 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 an event handler:

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

Add something like this to your 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 the references..

using Windows.Storage;
using Windows.Storage.Streams;
using Windows.ApplicationModel.Store;
using System.ComponentModel;
like image 152
A.J.Bauer Avatar answered Oct 14 '22 04:10

A.J.Bauer


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

like image 41
Nate Diamond Avatar answered Oct 14 '22 06:10

Nate Diamond