Quickstart: Setting up periodic notifications (HTML)

Note  Not using JavaScript? See Quickstart: Setting up periodic notifications (XAML).

 

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.

 

Prerequisites

Instructions

1. Create or identify a web service to host the tile's XML 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.

2. Place your tile content's XML file in a web-accessible location

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>

3. Begin the periodic updates (single URL)

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

4. Begin the periodic updates (multiple URLs)

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

Summary and next steps

This Quickstart walked you through the setup for a periodic tile notification.The same technique can be used on badges.

Push and Periodic Notifications sample

Guidelines for periodic notifications

How to use the notification queue with local notifications