Home > Articles > Mobile Application Development & Programming

Building Windows 8 Apps with JavaScript: Enabling Trial Mode in Your App

📄 Contents

  1. Introducing the Store API and Simulator
  2. Simulating and Testing Trial Functionality
  • Print
  • + Share This
  • 💬 Discuss
One of the great innovations that the Windows Phone ecosystem introduced to developers was platform-level support for trial apps. Not only does this save the store from being cluttered with tens of thousands of free or “lite” versions of paid apps, but it also enables developers to manage trial modes in their apps in the main codebase. From a consumer point of view, trial mode is a boon because you can take apps for a test drive before giving up your hard-earned cash.

Introducing the Store API and Simulator

Win8 style apps offer a similar capability via the Windows.ApplicationModel.Store namespace, which is your entry point into all relevant information about the user’s license for your app, including whether they are using a trial version and, if so, how much time they have left in that trial. To work with the Store API from your app, you’ll need to obtain a reference to the currentApp property on the Store namespace.

var currentApp = Windo ws.ApplicationModel.Store.CurrentApp;

The currentApp object is your programmatic gateway to the store; for licensing information, as well as for app metadata[md]like your app’s Store URL[md]and APIs for making in-app purchases. This object is quite handy at runtime on a user’s machine, but it contains nothing useful for developers during testing. For testing, we can use the CurrentAppSimulator object.

var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;

When you first access the CurrentAppSimulator object in your code, the runtime creates an XML file called WindowsStoreProxy.xml in the install folder (not the project folder) of your app, and pre-populates the file with dummy license data. You can find the file in the <install location>\LocalState\Microsoft\Windows Store\ApiData\ folder[1]. When you open the file, you’ll see information similar to the following.

<?xml version="1.0" encoding="utf-16" ?>
<CurrentApp>
    <ListingInformation>
        <App>
            <AppId>00000000-0000-0000-0000-000000000000</AppId>
            <LinkUri>http://store.windows.microsoft.com/app/00000000-0000-0000-0000-000000000000</LinkUri>
            <CurrentMarket>en-US</CurrentMarket>
            <AgeRating>3</AgeRating>
            <MarketData xml:lang="en-us">
                <Name>Tom8to</Name>
                <Description>The first Win8 style Pomodoro Timer</Description>
                <Price>1.99</Price>
                <CurrencySymbol>$</CurrencySymbol> 
                <CurrencyCode>USD</CurrencyCode>
            </MarketData>
        </App>
        <Product ProductId="1" LicenseDuration="0">
            <MarketData xml:lang="en-us">
                <Name>Product1</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>false</IsActive>
        </Product>
    </LicenseInformation>
</CurrentApp>

To simulate your app's behavior under certain conditions, like during a trial, or after a trial has elapsed, you can modify the elements and properties in this file, and the properties of the CurrentAppSimulator object will be changed accordingly when you access them at runtime. For example, let’s modify the LinkUri element above to point to a dummy Url:

<LinkUri>http://store.windows.microsoft.com/app/Tom8to</LinkUri> 

Now, when I access the LinkUri property on my currentApp object, I’ll see my Url reflected in the result, as shown in Figure 13.22.

Figure 13.22 Simulating Store Data with the CurrentAppSimulator object

When working with Store API functionality during development, you’ll want to use the CurrentAppSimulator since it’s easy to quickly change for testing, but don’t forget to change it back to using the CurrentApp object before submission, or your app will fail the WACK tool certification.


[1] Since this resource feels to me like a project level resource that should be versioned with an app during development, I’m personally hoping that the placement of this file in an install folder as opposed to your project folder is a Release Preview feature that will be corrected prior to launch.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus