IT tutorials
 
Technology
 

Windows Phone 8 : Using Push Notifications (part 6) - Handling Push Notification Errors

9/21/2013 2:09:41 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

7. Handling Push Notification Errors

When working with push notifications, you should also handle the ErrorOccurred event to deal with any exceptional conditions. You should always handle this event because it will help you locate badly formatted messages and low-battery issues that will stop push messages from working. You can handle this event like any other event:

_myChannel.ErrorOccurred += channel_ErrorOccurred;

The event passes in an error argument that has an ErrorType property that can be used to determine the type of error. You should change the way you alert the user to this based on the type of error. In addition, the handler should use the Dispatcher to ensure that any reporting of these errors occurs on the UI thread (as the ErrorOccurred event could be thrown on any thread):

void channel_ErrorOccurred(object sender,
                           NotificationChannelErrorEventArgs e)
{
  Deployment.Current.Dispatcher.BeginInvoke(() =>
  {
    switch (e.ErrorType)
    {
      case ChannelErrorType.ChannelOpenFailed:
        MessageBox.Show("Failed to open channel");
        break;
      case ChannelErrorType.NotificationRateTooHigh:
        MessageBox.Show("Push Notifications are too frequent.");
        break;
      case ChannelErrorType.PayloadFormatError:
        MessageBox.Show(@"XML or Headers were incorrect
                          for the Push Message");
        break;
      case ChannelErrorType.MessageBadContent:
        MessageBox.Show("Live Tile Data is invalid.");
        break;
      case ChannelErrorType.PowerLevelChanged:
        {
          MessageBox.Show(@"Push Notifications are
                            affected by the current power level");

          // Can get the power level from the event info
          ChannelPowerLevel level =
            (ChannelPowerLevel)e.ErrorAdditionalData;

          switch (level)
          {
            case ChannelPowerLevel.NormalPowerLevel:
              // All Push Messages are processed
              break;
            case ChannelPowerLevel.LowPowerLevel:
              // Only Raw Push Messages are processed
              break;
            case ChannelPowerLevel.CriticalLowPowerLevel:
              // No Push Messages are processed
              break;
          }
          break;
        }
    }
  });
}

The ChannelErrorType is returned in the event arguments and can be used to determine the error types. These error types are detailed in Table 3.

TABLE 3 ChannelErrorType Enumeration

Image

The PowerLevelChanged enumeration’s values are detailed in Table 4.

TABLE 4 ChannelPowerLevel Enumeration

Image
 
Others
 
- Windows Phone 8 : Using Push Notifications (part 5) - Creating Live Tiles
- Windows Phone 8 : Using Push Notifications (part 4) - Sending Toast Notifications
- Windows Phone 8 : Using Push Notifications (part 3) - Raw Notifications
- Windows Phone 8 : Using Push Notifications (part 2) - Setting Up the Server for Push Notifications
- Windows Phone 8 : Using Push Notifications (part 1) - Preparing the Application for Push Notifications
- InfoPath with SharePoint 2010 : Document Information Panel Content Type - Modify the DIP
- InfoPath with SharePoint 2010 : Document Information Panel Content Type - Create the Document Library, Add Columns to Your DIP
- Windows Small Business Server 2011 : Working with Users (part 4) - Creating User Roles
- Windows Small Business Server 2011 : Working with Users (part 3) - Managing User Properties
- Windows Small Business Server 2011 : Working with Users (part 2) - Creating Multiple User Accounts
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us