Windows store app: How to test in-app purchases

I just added a simple in-app purchase in my latest app to allow for the user to remove the advertisement. Before releasing the app I wanted to try the in-app purchase function to see if everything worked out as it should. To just try the function you simply have to change your

Windows.ApplicationModel.Store.CurrentApp

to

Windows.ApplicationModel.Store.CurrentAppSimulator

and run your purchase function. Simple enough.
But this testing function has a limitation in that it resets every time you start the app. I wanted to see how it looked after purchasing and then restarting the app (to make sure the ads were removed on start-up if the purchase had been made).

It turned out it could be done by finding a file on your computer that should be in the following path:

C:\Users\YOURUSERNAME\AppData\Local\Packages\YOURAPPGUID\LocalState\Microsoft\Windows Store\ApiData

where YOURUSERNAME is, well, your user name and YOURAPPGUID is the identifier for your app (find this in your package.appmanifest file in the packaging section). The file is called WindowsStoreProxy.xml and looks like this:

<?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">
            <MarketData xml:lang="en-us">
                <Name>Product1Name</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>
</CurrentApp>

I have highlighted the two lines that you need to edit. Change the ProductId to whatever you’ve named your “product” in your code to and you are ready to test your app with the purchases complete.

Note: If you happen to ruin the file in some way, just remove it and VS will generate a new one for you.

Windows 8: Using jQuery in your Windows Store app

Right, so I thought it would be great to write a HTML5 app in windows 8 since it’s supported and everything. The one thing I refuse to skip though is jQuery. So, I added jQuery 1.9.1 to my app, referenced it in my html-file and ran the app. The following popup showed up:

JavaScript runtime error: Unable to add dynamic content. A script attempted to inject dynamic content or elements previously modified dynamically that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content or explicitly create elements and attributes with a method such as createElement.
The error I received

I searched the web and I found that the only solution that seems safe at the time of writing is to use a “fixed” version for Windows 8, supplied by a company called AppendTo. The files can be downloaded here:
https://github.com/appendto/jquery-win8

Currently the latest jQuery release is 1.9.1 and the AppendTo conversion is 1.8.2 but it’s close enough and it works for me.

According to a couple of videos floating around and some articles on the subject the jQuery 2.0 release will have full support for Windows 8 so that should be great. But until then the AppendTo solution seems to be the best one out there.

Windows 8: App badge logo validation error

As I am almost done with my first Windows 8 App, Himmelsblå Dagar (a Swedish app), I was trying out the Windows App Cert Kit Tool used to validate your application before sending it into Microsoft. It was a good tool as it found two errors I had. One was that I was still building in Debug mode (doh!) and the other was the following:

Image reference “Assets\BadgeLogo.png”: The image “C:\Program Files\WindowsApps\XXX_1.0.0.0_neutral__123456789\Assets\BadgeLogo.png” has an ABGR value “0xFFDDEEFF” at position (0, 0) that is not valid. The pixel must be white (##FFFFFF) or transparent (00######).

I couldn’t figure out what the problem was as I wasn’t using transparency in my badge logo, just a really scaled down version of my normal logo icon. That was the problem. The badge logo can only use white (#FFFFFF) and transparency so I created a new logo using only the color white and it worked.

🙂

Windows 8: Updating a live tile from a PHP service

As I am making my first Windows 8 application I want to add a live tile. The application is a fixture list for my football team, Malmö FF, and I want it to have a live tile that always shows the next game.
I have all the games listed on a site that I’ve written in PHP which the full application uses to get the fixture list so I thought it would be neat if it could also generate the live tile.

I read up on how to create live tiles using the following two resources:
http://msdn.microsoft.com/en-us/library/windows/apps/hh761476.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx

It is possible to direct the update function to a URL which contains the XML for the live tiles. I’ve called the file Tile.php and it looks like this:

<?php
	$myLongHeader = "Hello dear world!";
	$myLongInfo1 = "I am a happy camper";
	$myLongInfo2 = date("y-m-d");
	$myLongInfo3 = ":)";
	
	$myShortHeader = "Hello!";
	$myShortInfo1 = "I am happy!";
	$myShortInfo2 = date("ymd");
?>
<tile>
  <visual>
    <binding template="TileWideText01">
      <text id="1"><?php echo $myLongHeader; ?></text>
      <text id="2"><?php echo $myLongInfo1; ?></text>
      <text id="3"><?php echo $myLongInfo2; ?></text>
	  <text id="4"><?php echo $myLongInfo3; ?></text>
    </binding>  
    <binding template="TileSquareText01">
      <text id="1"><?php echo $myShortHeader; ?></text>
      <text id="2"><?php echo $myShortInfo1; ?></text>
      <text id="3"><?php echo $myShortInfo2; ?></text>
    </binding> 
  </visual>
</tile>

This then generates the following XML (with the correct date of course):

<tile>
  <visual>
    <binding template="TileWideText01">
      <text id="1">Hello dear world!</text>
      <text id="2">I am a happy camper</text>
      <text id="3">13-04-07</text>
	  <text id="4">:)</text>
    </binding>  
    <binding template="TileSquareText01">
      <text id="1">Hello!</text>
      <text id="2">I am happy!</text>
      <text id="3">130407</text>
    </binding> 
  </visual>
</tile>

Notice that you can add both a large and a small tile. This is useful it seems that there will be support for even more sizes in the coming future according to Microsoft.
To use this from your application do the following in your C# code. You only have to do this once during the installation process of your application:

public class TileManager
{
	private const string Url = "http://mysite.com/services/Tile.php";

	public static void CreateUrlUpdater()
	{
		var recurrence = Windows.UI.Notifications.PeriodicUpdateRecurrence.HalfHour;
		var url = new Uri(Url);

		Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(url, recurrence);
	}
}

Windows 8: Task manager galore

I’ve installed Windows 8 and I had a couple of reasons for it:

  • I was running Windows Vista (need more reasons?)
  • It was cheap (special price, just for you and everyone else!)
  • I was interested in developing apps in C#

After installing Windows 8 I started hating it immediately as I was installing it before heading to bed and I couldn’t find the Shut down button. Also, it ran really slow on my old computer even though it passed Microsoft´s checklist just fine.
I finally found the shut down button soon enough and the next day I found some better drivers so the computer ran more smoothly. So, now I was gonna take a look around and I found the best thing since Microsoft killed of Clippy; the new Task Manager:

It’s a whole lot better then in previous versions of Windows and it gives you much more information about the current status of your computer and what’s running. It separates the information between desktop software and apps and it even has a “Simple View” if you just want to see what’s running:

This is great and I really like it!