Binding to the Shell

,

For the OS to display toast and tile notifications, the channel must call the BindToShellToast and BindToShellTile methods, as demonstrated in the following excerpt:

/* Toast Notifications. */
if (!channel.IsShellToastBound)
{
    channel.BindToShellToast();
}

/* Tile Notifications. */
if (!channel.IsShellTileBound)
{
    channel.BindToShellTile();
}

To stop receiving toast and tile notifications, the channel provides the UnbindToShellToast and UnbindToShellTile methods, respectively.


Best Practice

When creating an HttpNotificationChannel, avoid keeping it open if not subscribing to its events. It is not necessary for the channel to be kept open for the shell to receive either toast or tile notifications, and the channel itself consumes valuable resources.

HttpNotificationChannel implements IDisposable and can be safely disposed after binding it to the shell, as shown in the following excerpt:

using (HttpNotificationChannel channel
     = new  HttpNotificationChannel(channelName))
{
    channel.Open();
    channel.BindToShellTile();
    channel.BindToShellToast();
}



Note

Calling the Open method on a channel may immediately raise an Exception, most commonly an InvalidOperationException, if the channel fails to establish a connection with the MPNS.


After retrieving or creating a channel instance, you are able to subscribe to its various events.


Caution

Be mindful that each Windows Phone device is limited to a total of 15 apps registered for push notifications. If the user installs 15 apps that use push notifications and your app is the 16th one installed, an InvalidOperationException (channel quota exceeded) is raised if your app calls BindToShellTile or BindToShellToast.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.151.21