This topic shows you how to launch periodic polling of a URL to get updated content for your app's tile.
We recommend that all polled notifications make use of the X-WNS-Expires HTTP response header to set an explicit expiration time. For more information on setting X-WNS-Expires, see TileUpdater.StartPeriodicUpdate or TileUpdater.StartPeriodicUpdateBatch.
Note In this Quickstart you'll manipulate the notification content directly through the XML Document Object Model (DOM). An optional approach is available through the NotificationsExtensions library, which presents the XML content as object properties, including Intellisense. For more information, see Quickstart: Using the NotificationsExtensions library in your code. To see the code in this Quickstart expressed using NotificationsExtenstions, see the Push and periodic notifications sample.
- A working knowledge of tile and notification terms and concepts. For more information, see Tiles, Badges, and Notifications.
- An understanding of periodic (polling) notification concepts. For more information, see Periodic notification overview
- A web service to host the tile notification content.
At a specified interval, Windows will poll the specified web service for updated tile content for your app. The web service must support HTTP. For testing, you can also set up a web service, such as Microsoft Internet Information Services (IIS) on your local machine to test the XML.
Your web service will host the tile XML content. To get started, host the tile XML shown here on your web site. Save this content as a file named Tile.xml and place the file on the server in a web-accessible location (for example, http://www.fabrikam.com/tile.xml). The contents of the XML document must use a UTF-8 encoding and conform to the tile schema. You should update this XML at least as frequently as the specified polling recurrence interval.
<tile> <visual version="2"> <binding template="TileSquare150x150Text04" fallback="TileSquareText04"> <text id="1">Hello world!</text> </binding> </visual> </tile>
This example shows how to start polling a single URL to provide new content for the tile once an hour. This code uses a previously defined variable called
polledUrl, which is a string that specifies the URL to be polled.
var notifications = Windows.UI.Notifications; var recurrence = notifications.PeriodicUpdateRecurrence.hour; var url = new Windows.Foundation.Uri(polledUrl); notifications.TileUpdateManager.createTileUpdaterForApplication().startPeriodicUpdate(url, recurrence);
As an alternative to the previous step, Windows can poll up to five different URLs to supply a set of content that cycles through the tile's notification queue.
This example shows how to poll multiple URLs for new content once an hour. First, you must enable the notification queue if you have not enabled it previously. Note that the call to enableNotificationQueue should be made only one time after the user installs the app or creates a secondary tile. This example code uses a previously defined variable called
urisToPoll, which is an array of Windows.Foundation.Uri objects.
Note Periodic tile updates support the tile notification tag that is part of the notification queue replacement logic. Your service can set the tag on each notification by providing the X-WNS-Tag HTTP response header. For more information on using tags and the notification queue, see How to use the notification queue with local notifications. For more information on using the X-WNS-Tag HTTP response header with periodic notifications, see TileUpdater.startPeriodicUpdateBatch.
var notifications = Windows.UI.Notifications; var recurrence = notifications.PeriodicUpdateRecurrence.hour; notifications.TileUpdateManager.createTileUpdaterForApplication().enableNotificationQueue(true); notifications.TileUpdateManager.createTileUpdaterForApplication().startPeriodicUpdateBatch(urisToPoll, recurrence);
- Push and Periodic Notifications sample
- Guidelines for periodic notifications
- How to use the notification queue with local notifications