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);
	}
}

Leave a Reply