180 likes | 297 Views
Push Notification Services. Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP. http:// mobileworld.appamundi.com/blogs/andywigley/rss.aspx. andy.wigley@appamundi.com. Push Notifications. Server-initiated Communication.
E N D
Push Notification Services Andy Wigley APPA Mundi Microsoft Windows Phone Development MVP http://mobileworld.appamundi.com/blogs/andywigley/rss.aspx andy.wigley@appamundi.com
Push Notifications Server-initiated Communication • 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
Live Tiles • Shortcuts to apps • Static or dynamic • 2 sizes: small & large • “Pin to Start”
Notification Toasts App icon + 2 text fields Interruptive, transient and chase-able Time critical and personally relevant Users must opt-in via app UI
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
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
Push Notification Data Flow 2 URI to the service: "http://notify.live.com/throttledthirdparty/01.00/AAFRQHgiiMWNTYrRDXAHQtz-AgrNpzcDAwAAAAQOMDAwMDAwMDAwMDAwMDA" 3rd party service Push enabled application 3 Notifications service HTTP POST the message 4 Send PN Message 1 Microsoft hosted server Push endpoint is established. URI is created for the endpoint.
RawMessage 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; • }
string toastMessage= "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notificationxmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1><string></wp:Text1>" + "<wp:Text2><string></wp:Text2>" + "</wp:Toast>" + "</wp:Notification>"; Toast Message Content • 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>
string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notificationxmlns: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>"; Tile Message Content • 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
Building a Push Notification Service Demo Using the Push Notification Server-Side Helper Library
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
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
Scheduling Tile Update • public 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(); • } • }
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.