Windows Phone 8.1 and CurrentAppSimulator
Asked Answered
S

3

5

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?

Sining answered 7/9, 2014 at 0:6 Comment(0)
B
9
  • 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;
Benzene answered 25/11, 2014 at 9:6 Comment(1)
Thanks for the detailed info! I got it to display the dialog and raise the events. Nevertheless, I'm unsure what to do with it. When I request the feature twice in a row, I have the feeling that the purchase is not propagated. How should I tell the LicenseInformation object that the app is not in trial mode anymore? Thanks!Nacreous
S
1

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.

Sining answered 7/9, 2014 at 0:6 Comment(0)
V
0

More in detail in the previous answer:

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

2.Set in property file "the output directory to copy" - "copy a newer 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();
    }
    
Veasey answered 17/11, 2015 at 4:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.