push notification: come rendere vive le app su windows phone
TRANSCRIPT
![Page 1: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/1.jpg)
WP0703 – Push Notification: come rendere vive le app su Windows Phone
Raffaele [email protected]@raffaelefanizzihttp://www.vifani.com
#CDays12BA – 8 e 9 maggio
![Page 2: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/2.jpg)
Grazie aSponsor
![Page 3: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/3.jpg)
Agenda• Introduzione
• Tipi di Push Notification
• Comunicazioni e Limitazioni
• Ricevere ed Inviare Push Notification
• Demo
• Q&A
![Page 4: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/4.jpg)
Introduzione• Cosa sono le Push
Notification?– Un modo per inviare
periodicamente informazioni alle vostre applicazioni anche quando non sono attive
![Page 5: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/5.jpg)
Introduzione• Perché le Push Notification?
Per evitare la pratica del
polling
Per preservare l’autonomia
dei dispositivi
Per migliorare
l’esperienza d’uso delle
app
![Page 6: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/6.jpg)
Architettura
HTTP Post to URI with payload
Push URI request/response
Push enabled
application
Push client service
Push client/server negotiation
2
Push URI to Cloud Servic
e 4
5Push notification to
device6
Custom Server
MPNS
Windows Phone 7
13
![Page 7: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/7.jpg)
Tipi di Push Notification• Toast Notification
• Tile Notification
• Raw Notification
![Page 8: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/8.jpg)
Toast Notification• Composte da– Title
– Content
– Parameter
![Page 9: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/9.jpg)
Toast Notification• Funzionalità– Possono essere inviate
immediatamente o con un ritardo di 450 o 900 secondi
– Possono essere gestite anche se l’app è attiva
![Page 10: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/10.jpg)
Toast Notification• Limiti– L’icona non è
modificabile
– La quantità di testo tra titolo e contenuto visualizzabile è pari a circa 40 caratteri
![Page 11: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/11.jpg)
Toast Notification• Messaggio XML
<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification"> <wp:Toast>
<wp:Text1>Title</wp:Text1><wp:Text2>Content</wp:Text2><wp:Param>Param</wp:Param>
</wp:Toast> </wp:Notification>
![Page 12: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/12.jpg)
Tile Notification• Composta da– Title
– Count (badge)
– Backgr. Image
– Back Title
– Back Content
– Back Backgr. Image
![Page 13: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/13.jpg)
Tile Notification• Funzionalità– Possono essere inviate
immediatamente o con un ritardo di 450 o 900 secondi
– Possono aggiornare sia la tile principale dell’app, sia le tile secondarie
![Page 14: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/14.jpg)
Tile Notification• Limiti
– Le immagini devono essere:• risoluzione 173x173
• formato JPG o PNG
– Le immagini possono essere locali (nello XAP) o remote
– Le immagini caricate da remoto devono essere:• Massimo 80 KB
• Disponibili entro 30 secondi
• Su protocollo http e non https
![Page 15: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/15.jpg)
Tile Notification• Messaggio XML
<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification"> <wp:Tile>
<wp:BackgroundImage>image1.jpg</wp:BackgroundImage>
<wp:Count>1</wp:Count><wp:Title>Title1</wp:Title><wp:BackBackgroundImage>image2.jpg</
wp:BackBackgroundImage><wp:BackTitle>BackTitle1</wp:BackTitle><wp:BackContent>Content1</wp:BackContent>
</wp:Tile> </wp:Notification>
![Page 16: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/16.jpg)
Raw Notification• Non hanno una struttura
definita
• Consentono di inviare all’app informazioni in formato XML
• Sono ricevute dall’app solo se è in esecuzione
![Page 17: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/17.jpg)
Raw Notification• Messaggio XML
<?xml version="1.0" encoding="utf-8"?><root>
<Value1>v1</Value1><Value2>v2</Value2>
</root>
![Page 18: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/18.jpg)
Comunicazioni• E’ possibile inviare notifiche da un proprio web
service sia in forma autenticata, che non autenticata
• Se il web service è anonimo non sarà possibile generare più di 500 notifiche al giorno per sottoscrizione
• Un web service autenticato può anche registrarsi al servizio di callback Microsoft che notifica il cambio di stato di un device
![Page 19: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/19.jpg)
Limitazioni• Tecniche
– Massimo un canale di comunicazione per applicazione
– Massimo 30 canali di comunicazione per device
– Massimo 1 KB per l’header e 3 KB per il body
• Certificazione dell’app– L’app deve sempre comunicare all’utente che si sta
registrando al servizio di Push Notification
– L’app deve sempre fornire all’utente la possibilità di cancellare la registrazione dal servizio
![Page 20: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/20.jpg)
Ricevere Push Notification• Cosa è necessario fare?– Registrare l’app alla ricezione di una Push
Notification
– Inviare il Channel Uri ad un vostro servervar pushChannel = HttpNotificationChannel.Find(channelName);pushChannel = pushChannel ?? new HttpNotificationChannel(channelName);pushChannel.ChannelUriUpdated += (s,e) => { SendToServer(e.ChannelUri); };pushChannel.Open(); pushChannel.BindToShellTile(); //Register to receive tile notificationpushChannel.BindToShellToast(); //Register to receive toast notification
![Page 21: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/21.jpg)
Inviare Push Notification• Cosa è necessario fare?– Creare ed eseguire una chiamata HTTP di tipo
POST verso il channel uri//Create RequestHttpWebRequest request = (HttpWebRequest)WebRequest.Create(device.UrlNotification); request.Method = "POST";
//Create Message (depends on notification type)string message = "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification xmlns:wp=\"WPNotification\"> ….
//Define request bodyAddBodyToRequest(request, message);
//Send request and get responseHttpWebResponse response = (HttpWebResponse)request.GetResponse();
![Page 22: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/22.jpg)
Inviare Push Notification• Push Notification Server Side Helper– Libreria opensource che semplifica
l’invio dei messaggi lato server
– Incapsula la generazione dei messaggi XML in classi
• Disponibile su http://bit.ly/wp7pushlib
![Page 23: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/23.jpg)
Demo
var demo = new PushNotificationDemo() { OnError = ()=> { Says(‘It’s a Windows Error ’); }, OnSuccess = ()=> { BackToSlides(); }}
demo.Show();
![Page 25: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/25.jpg)
Riferimenti• Il mio blog
http://www.vifani.com
• DotNetSidehttp://dotnetside.org
• MSDNhttp://msdn.microsoft.com
![Page 26: Push Notification: come rendere vive le app su Windows Phone](https://reader035.vdocuments.mx/reader035/viewer/2022062319/558a1d6ed8b42ae4178b463f/html5/thumbnails/26.jpg)
Grazie per l’attenzione