push notification: come rendere vive le app su windows phone

Post on 24-Jun-2015

1.066 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

WP0703 – Push Notification: come rendere vive le app su Windows Phone

Raffaele Fanizzivifani@gmail.com@raffaelefanizzihttp://www.vifani.com

#CDays12BA – 8 e 9 maggio

Agenda• Introduzione

• Tipi di Push Notification

• Comunicazioni e Limitazioni

• Ricevere ed Inviare Push Notification

• Demo

• Q&A

Introduzione• Cosa sono le Push

Notification?– Un modo per inviare

periodicamente informazioni alle vostre applicazioni anche quando non sono attive

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

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

Tipi di Push Notification• Toast Notification

• Tile Notification

• Raw Notification

Toast Notification• Composte da– Title

– Content

– Parameter

Toast Notification• Funzionalità– Possono essere inviate

immediatamente o con un ritardo di 450 o 900 secondi

– Possono essere gestite anche se l’app è attiva

Toast Notification• Limiti– L’icona non è

modificabile

– La quantità di testo tra titolo e contenuto visualizzabile è pari a circa 40 caratteri

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>

Tile Notification• Composta da– Title

– Count (badge)

– Backgr. Image

– Back Title

– Back Content

– Back Backgr. Image

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

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

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>

Raw Notification• Non hanno una struttura

definita

• Consentono di inviare all’app informazioni in formato XML

• Sono ricevute dall’app solo se è in esecuzione

Raw Notification• Messaggio XML

<?xml version="1.0" encoding="utf-8"?><root>

<Value1>v1</Value1><Value2>v2</Value2>

</root>

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

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

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

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();

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

Demo

var demo = new PushNotificationDemo() { OnError = ()=> { Says(‘It’s a Windows Error ’); }, OnSuccess = ()=> { BackToSlides(); }}

demo.Show();

Q&A• Materiale su

http://www.communitydays.it/

Riferimenti• Il mio blog

http://www.vifani.com

• DotNetSidehttp://dotnetside.org

• MSDNhttp://msdn.microsoft.com

Grazie per l’attenzione

top related