Quickstart: Setting up periodic notifications (XAML)
Note Not using C#/VB/C++? See Quickstart: Setting up periodic notifications (HTML).
This topic shows you how to launch periodic polling of a URL for 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 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
- The ability to create a basic Windows Store app with C# or C++ Microsoft Visual Basic using Windows Runtime APIs. For more information, see Create your first Windows Store app using C# or Visual Basic.
- Understanding of how to create a code-behind for a Windows Store app with Extensible Application Markup Language (XAML).
- Familiarity with XML.
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.
using namespace Windows::UI::Notifications; using namespace Windows::Foundation; PeriodicUpdateRecurrence recurrence = static_cast<PeriodicUpdateRecurrence>(Hour); Uri^ url = ref new Uri(polledUrl); 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 URL objects, each of which represents a different URL from which to get polled content.
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.
using namespace Windows::UI::Notifications; using namespace Windows::Foundation; TileUpdateManager::CreateTileUpdaterForApplication()->EnableNotificationQueue(true); PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence::Hour; TileUpdateManager::CreateTileUpdaterForApplication()->StartPeriodicUpdateBatch(urisToPoll, recurrence);
- Push and Periodic Notifications sample
- Guidelines for periodic notifications
- How to use the notification queue with local notifications