Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

18
ONLINE CONFERENCE DESIGN.BUILD.DELIV ER with WINDOWS PHONE THURSDAY 24 MARCH 2011

description

Push Notification Services. Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP. http:// mobileworld.appamundi.com/blogs/andywigley/rss.aspx. [email protected]. Push Notifications. Server-initiated Communication. - PowerPoint PPT Presentation

Transcript of Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Page 1: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

ONLINE CONFERENCE

DESIGN.BUILD.DELIVERwith WINDOWS PHONE

THURSDAY 24 MARCH 2011

Page 2: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Andy WigleyAPPA MundiMicrosoft Windows Phone Development MVP

http://mobileworld.appamundi.com/blogs/andywigley/rss.aspx

[email protected]

Push Notification Services

Page 3: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Server-initiated Communication

Push Notifications

Your web service sends messages to phones where your push notification-enabled app is installed

• Server-initiated so app does not have to poll server• Battery friendly• Provide alerts in the app, toast popup alerts or live

tile updates

• Provide a real-time data feed capability to your app• Enhance user experience

Page 4: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

4

Live Tiles

• Shortcuts to apps

• Static or dynamic

• 2 sizes: small & large

• “Pin to Start”

Page 5: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

5

Notification Toasts

Interruptive, transient and chase-able App icon + 2 text fields

Time critical and personally relevant Users must opt-in via app UI

Page 6: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Raw Notifications• Notification message

content is application-specific

• Delivered directly to app only if it is running

• How you use the message content is application-specific

Page 7: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

7

Three Kinds of Notifications• Tile

– Specific XML schema– Never delivered to app – If user has pinned app tile to Start screen, system

updates it using notification message content• Toast

– Specific XML schema– Content delivered to app if it is running– If app is not running, system displays Toast popup

using notification message content• Raw

– Notification message content is application-specific– Delivered directly to app only if it is running

Page 8: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Push Notification Data Flow

8

URI to the service:"http://notify.live.com/throttledthirdparty/01.00/AAF

RQHgiiMWNTYrRDXAHQtz-AgrNpzcDAwAAAAQOMDAwMDAwMDAwMDAwMDA"Push enabled

application

Notifications service HTTP POST the

message

Push endpoint is established. URI is created for the endpoint.

1

2

3

3rd party service

Microsofthosted server

Send PN Message

4

Page 9: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

9

Raw Message Content• Message Content is application-specific – only gets delivered

to running app• For example use XML to format data

private static byte[] prepareRAWPayload(string location, string temperature, string weatherType){ MemoryStream stream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings() { Indent = true, Encoding = Encoding.UTF8 }; XmlWriter writer = XmlTextWriter.Create(stream, settings);

writer.WriteStartDocument(); writer.WriteStartElement("WeatherUpdate");

writer.WriteStartElement("Location"); writer.WriteValue(location); writer.WriteEndElement();... writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close();

byte[] payload = stream.ToArray(); return payload;}

Page 10: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

10

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

Used by system to display Toast message if app not running

ShellToastNotificationReceived event fires if app is running <Text1> and <Text2> values in

event args as Dictionary<string, string>

Page 11: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

11

Tile Message Contentstring tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +"<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Tile>" + "<wp:BackgroundImage><background image path></wp:BackgroundImage>" + "<wp:Count><count></wp:Count>" + "<wp:Title><title></wp:Title>" + "</wp:Tile> " +"</wp:Notification>";

Never delivered to app <background image path>, <count>, and <title>

are in a string format Maximum allowed size of the tile image referenced

in <background image path> is 80 KB, with a maximum download time of 1 minute

Page 12: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Server Side Helper Recipe

Page 13: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

13

Building a Push Notification Service

Using the Push Notification Server-Side Helper Library

Demo

Page 14: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Response Custom Headers• Response Code: HTTP status code (200 OK)• Notification Status

– Notification received by the Push Notification Service– For example: “X-NotificationStatus:Received”

• DeviceConnectionStatus– The connection status of the device– //For example: X-DeviceConnectionStatus:Connected

• SubscriptionStatus– The subscription status– //For example: X-SubscriptionStatus:Active

• More information – http://msdn.microsoft.com/en-us/library/ff402545(v=VS.

92).aspx

Page 15: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

15

Tile Schedule• Periodically updates the tile image without

requiring a Push Notification message• Updates images only from the web, not

from the app local store• Few limitations

– Image size must be less than 80 KB– Download time must not exceed 60 seconds– Lowest update time resolution is up to 60

minutes

Page 16: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

16

Scheduling Tile Updatepublic partial class MainPage : PhoneApplicationPage {    private ShellTileSchedule _mySchedule;    public MainPage()   {        InitializeComponent();        ScheduleTile();    }

     private void ScheduleTile()    {        _mySchedule = new ShellTileSchedule();        _mySchedule.Recurrence = UpdateRecurrence.Onetime;        _mySchedule.StartTime = DateTime.Now;        _mySchedule.RemoteImageUri = new Uri("http://cdn3.afterdawn.fi/news/small/windows-phone-7-series.png");        _mySchedule.Start();    }}

Page 17: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

Thank You for attending today’s Tech.Days Online Conference.

Today’s Online Conference will be recorded. It will be made available on-demand very soon.

Your Feedback Matters! Please complete the online evaluation form which will be emailed to you.

Page 18: Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

ONLINE CONFERENCE