Roberto Brunetti Mobile Blog

Bridging the Mobility Gap !

Recent Posts

Tags

Community

Email Notifications

.NET Blogs

Archives

Push Notification: cambio formato

E’ cambiato il formato per l’invio delle notifiche Toast e Tile. E’ rimasto invariato il formato per le notifiche Raw.

Non occorre modificare il codice lato telefono, ma solo il codice lato receiver.

Toast

Il codice seguente, dove notificationMessage, è il messaggio da inviare e sendNotificationRequest l’oggetto HttpWebRequest.

notificationMessage = "Content-Type: text/xml\r\nX-WindowsPhone-Target: toast\r\n\r\n" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  "<wp:Notification xmlns:wp=\"WPNotification\">" +
          "<wp:Toast>" +
              "<wp:Text1>" + title + "</wp:Text1>" +
          "</wp:Toast>" +
  "</wp:Notification>";

sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");

Deve essere modificato con

string notificationMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  "<wp:Notification xmlns:wp=\"WPNotification\">" +
          "<wp:Toast>" +
              "<wp:Text1>Ciao</wp:Text1>" +
              "<wp:Text2>Roberto</wp:Text2>" +
          "</wp:Toast>" +
  "</wp:Notification>";

sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");

Tile

Anche nei tile è cambiato qualcosa, ma in modo leggermente diverso.

Vecchio codice:

notificationMessage = "Content-Type: text/xml\r\nX-WindowsPhone-Target: token\r\n\r\n" +
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Tile>” +
           “<wp:BackgroundImage>" + imagePath + "</wp:BackgroundImage>";
           notificationMessage += "<wp:Count>" + count + "</wp:Count>";
           notificationMessage += "<wp:Title>" + title + "</wp:Title>";
           notificationMessage += "</wp:Token>" +
    "</wp:Notification>";

Nuovo codice (si perde la definizione Content-Type, ma non si cambiano gli header rispetto a Toast)

notificationMessage = "Content-Type: text/xml\r\nX-WindowsPhone-Target: token\r\n\r\n" +
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Tile>” +
           “<wp:BackgroundImage>" + imagePath + "</wp:BackgroundImage>";
           notificationMessage += "<wp:Count>" + count + "</wp:Count>";
           notificationMessage += "<wp:Title>" + title + "</wp:Title>";
           notificationMessage += "</wp:Tile>" +
    "</wp:Notification>";

Comments

Roberto Brunetti Mobile Blog said:

Il 15/6 avevo avuto l’opportunità di tenere fra le mani un prototipo del nuovo device durante un incontro

# August 16, 2010 6:27 AM