23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

containing the app’s purchase price formatted for the user’s current market and currency), name (a string<br />

with the app’s name in the current market), and productListings. The latter is an array of<br />

ProductListing objects, each of which contains just three properties: productId (a string containing<br />

the app-defined product identifier), formattedPrice (a localized string containing the product price),<br />

and a localized name (a string). You can see that this collection is exactly what you’ll use to present the<br />

user with a localized list of options they can purchase, where the productId could be used to retrieve<br />

additional content like images from your package or a web service.<br />

The LicenseInformation object for its part contains simple properties of expirationDate (a Date),<br />

isActive (a Boolean), and isTrial (a Boolean). It has one event, licenseChanged, which you can use to<br />

detect any changes to these properties, such as the expiration of a license while the app is running, in<br />

which case you want to prompt for purchase. The remaining property, productLicenses, is a collection<br />

of ProductLicense objects. Each of these contains the appropriate productId, expirationDate, and<br />

isActive properties.<br />

Tip For globalization purposes, never compare two dates with simple arithmetic operators like ,<br />

and =. Instead. Use the Windows.Globalization.Calendar.compareDateTime method, which will<br />

account for the specific needs of different calendar systems that might be in effect.<br />

That’s really the extent of the Store APIs in a nutshell. You may notice, by the way, that the APIs don’t<br />

concern themselves with ad-supported apps, since ads don’t involve the Store itself.<br />

But you might be asking yourself some very significant questions: how on earth can this API return<br />

any meaningful information while the app is under development and has yet to be uploaded to the<br />

Store in the first place? How can you get product information and test all your purchase features when<br />

there’s nothing yet available to purchase?<br />

These are great questions, and the answer lies in the one other object in the<br />

Windows.ApplicationModel.Store namespace that is our next topic: the Windows Store app simulator.<br />

The CurrentAppSimulator Object<br />

To make it possible to test an app’s interactions with the Store before the app is actually onboarded,<br />

WinRT provides the static CurrentAppSimulator object that is identical to CurrentApp with two<br />

exceptions: the simulator object works against data from a local XML file rather than live data from the<br />

Store, and the object has an extra method, reloadSimulatorAsync, to reinitialize the simulator with such<br />

XML. During development, you’ll want to use this line of code to start your work with the API:<br />

var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;<br />

and then delete the Simulator suffix when you’re ready to send the app to the Store. (And if you forget,<br />

you’ll fail Store certification.)<br />

770

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!