Local, scheduled, periodic and push updates.

35
Alive with activity Tiles, notifications, and background tasks Kraig Brockschmidt Senior Program Manager, Windows Ecosystem Team Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript 3-101

Transcript of Local, scheduled, periodic and push updates.

Page 1: Local, scheduled, periodic and push updates.

Alive with activityTiles, notifications, and background tasksKraig BrockschmidtSenior Program Manager, Windows Ecosystem TeamAuthor, Programming Windows 8 Apps with HTML, CSS, and JavaScript3-101

Page 2: Local, scheduled, periodic and push updates.

Visual tour: understanding the user experienceThree ways an app configures updatesThe role of background tasks for notificationsWriting and debugging web services for notifications

Agenda

Page 3: Local, scheduled, periodic and push updates.

How do we create an environment that’s “alive with

activity”without having apps running

all the time?

Page 4: Local, scheduled, periodic and push updates.

Demo: a visual tour

Page 5: Local, scheduled, periodic and push updates.

Live tiles

Updates include both square and wide tiles

Tiles updated using pre-defined templates

Text-only, image-only or combination

JPEG, GIF, or PNG, max size 200 KB, max 1024px size

Optional “peek” animation

Local, scheduled, periodic and push updates

Page 6: Local, scheduled, periodic and push updates.
Page 7: Local, scheduled, periodic and push updates.

Toast templates

Page 8: Local, scheduled, periodic and push updates.

The lock screen

App content

Page 9: Local, scheduled, periodic and push updates.

Alive with activity without apps running

Issue direct updates, perhaps using queue, scheduled, and expiring updates

Tell Windows a service URL where it can to obtain periodic updates

Obtain a Windows Push Notification Service (WNS) channel and have a service send notifications to that

These actions can happen from app code or background tasks

There are three ways an app configures thisto happen

Page 10: Local, scheduled, periodic and push updates.

What makes an update?

Choices: Tile template catalog, badge catalog, toast template catalog, plus Toast audio options catalog

Whoever issues an update builds the XMLURIs for images can use http[s]://, ms-appx:///, orms-appdata:///local/

Notifications Extensions Library providesan object modelReduces mistakes that cause updates to not show

Tiles, badges, and toasts are bits of XML that come from predefined templates (to avoid chaos)

Page 11: Local, scheduled, periodic and push updates.

XML badge update schema<?xml version="1.0" encoding="utf-8" ?><badge value = "1-99" | "none" | "activity" | "alert" | "available" | "away" | ... version? = "integer" />

Page 12: Local, scheduled, periodic and push updates.

XML tile update schema<?xml version="1.0" encoding="utf-8" ?><tile> <visual version? = "integer" lang? = "string" baseUri? = "anyURI" branding? = "none" addImageQuery? = "boolean" >

<!-- One or more binding elements --> <binding template = "TileSquareImage" | "TileSquareBlock" | ... fallback? = "string" lang? = "string" baseUri? = "anyURI" branding? = "none" addImageQuery? = "boolean" >

<!-- Some combination of image and text --> <image id = "integer" src = "string" alt? = "string" addImageQuery? = "boolean" /> <text id = "integer" lang? = "string" /> </binding> </visual></tile>

Page 13: Local, scheduled, periodic and push updates.

XML toast notification schema<?xml version="1.0" encoding="utf-8" ?><toast launch? = "string" duration? = "long" | "short" > <visual version? = "integer" lang? = "string" baseUri? = "anyURI" branding? = "none" addImageQuery? = "boolean" >

<!-- One or more bindings --> <binding template = "ToastImageAndText01" | "ToastImageAndText02" | ...="" fallback? = "string" lang? = "string" baseUri? = "anyURI" branding? = "none" addImageQuery? = "boolean" >

<!-- Some number of child elements --> <image id = "integer" src = "string" alt = "string" addImageQuery? = "boolean" /> <text id = "integer" lang? = "string" /> </binding> </visual>

<!-- Optional audio --> <audio src? = "ms-winsoundevent:Notification.Default" |... loop? = "boolean" silent? = "boolean" /></toast>

Page 14: Local, scheduled, periodic and push updates.

Secondary tiles

Tiles created by “pinning” content from app

Pin initiated by app via simple runtime call

User confirms pin operation via system UI

Exposes a personalized surface for app

Increases Start screen presence

Same capabilities as app tiles

Launch leads to relevant content

See Windows.UI.StartScreen.SecondaryTiles classand Secondary Tiles Sample

Page 15: Local, scheduled, periodic and push updates.

Issuing updates from the app

Running app orbackground

task

Tile and badge API

toast API

In Windows.UI.Notifications namespace:TileNotification >> TileUpdater, SecondaryTileUpdaterBadgeNotification >> BadgeUpdaterToastNotification >> ToastNotifier

Updates appear immediately

Page 16: Local, scheduled, periodic and push updates.

Scheduled notifications

In Windows.UI.Notifications namespace:ScheduledTileNotification >> TileUpdater, SecondaryTileUpdaterScheduledToastNotification >> ToastNotifier

Running app or

background task

Scheduled notification API

Queue

System process

Suspendedor not running

Page 17: Local, scheduled, periodic and push updates.

Configuring periodic updates

In Windows.UI.Notifications namespace:TileUpdater.StartPeriodicUpdate and StartPeriodicUpdateBatchBadgeUpdater.StartPeriodicUpdate

Running app or

background task

Tile and badge updater API

System process30m to 24h frequency per service

Suspendedor not running

URI

web service

HTTP Request

Page 18: Local, scheduled, periodic and push updates.

Demo: writing and debugging aperiodic update service

Page 19: Local, scheduled, periodic and push updates.

Configuring push notifications

Running app: PushNotificationChannel.PushNotificationReceived event(in Windows.Networking.PushNotifications namespace)

Background task: PushNotificationTrigger

Running app or

background task

Channel request API

Suspendedor not running

Send channel to web service

WNS

Sendupdate

Push updatesto client (tile, badge,toast, raw)

web service

Page 20: Local, scheduled, periodic and push updates.

Register the app via Store dashboard

Page 21: Local, scheduled, periodic and push updates.

Demo: writing and debugging aservice for WNS

Page 22: Local, scheduled, periodic and push updates.

Building a Cloud Service with Window Azure

How do I do that with Windows Azure?

Windows Azure Mobile Services

www.WindowsAzure.com/mobile

11/1 4:15pm - Baker – Windows 8 Connectathon with Windows Azure Mobile Services (3-129)

Also see offerings from Urban Airship:http://urbanairship.com

What a push service needs to support:

Secure service API for channel URI registration

Persistent storage ofchannel URIs

Storage for tile andtoast images

Building a cloud service withWindows Azure

Page 23: Local, scheduled, periodic and push updates.

Background tasks for notificationsMaintenance triggers – monitor state changes, renew WNS channelsSystem triggers - AC power, non-lock screen

InternetAvailable, NetworkStateChange for connectivityLockScreenApplication[Added | Removed]ServicingComplete app has been updated

Lock screen triggers - AC or battery powerControlChannelTrigger (sockets for RTC), TimeTrigger,SessionConnected, UserAway, UserPresentPushNotificationTrigger to receive raw notifications

All tasks subject to CPU and network activity quotasIndependent of main app (can use mixed languages)

Page 24: Local, scheduled, periodic and push updates.

Renewing WNS channels (register task, C#)using Windows.ApplicationModel.Background;

BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();MaintenanceTrigger trigger = new MaintenanceTrigger( 10 * 24 * 60, false); //10 * 24 * 60 == 10 daystaskBuilder.SetTrigger(trigger);//In JavaScript, taskEntryPoint is the path of a .js filetaskBuilder.TaskEntryPoint = "PushNotificationsHelper.MaintenanceTask";taskBuilder.Name = "UpdateChannels";

SystemCondition internetCondition = new SystemCondition( SystemConditionType.InternetAvailable);taskBuilder.AddCondition(internetCondition);taskBuilder.Register();

Page 25: Local, scheduled, periodic and push updates.

Renewing WNS channels (task, C#)using System;using System.Threading.Tasks;using Windows.ApplicationModel.Background;

namespace PushNotificationsHelper { public sealed class MaintenanceTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // This is a helper function to renew WNS channels. // Important here to not block the UI thread. Notifier notifier = new Notifier(); notifier.RenewAllAsync(false).AsTask().Wait(); } }}

Page 26: Local, scheduled, periodic and push updates.

Renewing WNS channels (task, JavaScript)// This code runs as a web worker(function () { // Import the Notifier helper object importScripts("//Microsoft.WinJS.1.0/js/base.js"); importScripts("notifications.js");

var closeFunction = function () { close(); // This is worker.close };

var notifier = new SampleNotifications.Notifier(); notifier.renewAllAsync().done(closeFunction, closeFunction);})();

Page 27: Local, scheduled, periodic and push updates.

Receiving raw notification (register task, C#)using Windows.ApplicationModel.Background;using Windows.Networking.PushNotifications;

BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();PushNotificationTrigger trigger = new PushNotificationTrigger();taskBuilder.SetTrigger(trigger);taskBuilder.TaskEntryPoint = "BackgroundTasks.RawNotification";taskBuilder.Name = "ReceiveRawNotification";taskBuilder.Register();

Page 28: Local, scheduled, periodic and push updates.

Receiving raw notification (task, C#)using System.Diagnostics;using Windows.ApplicationModel.Background;using Windows.Networking.PushNotifications;using Windows.Storage;

namespace BackgroundTasks { public sealed class RawNotification : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Get the background task details ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;

// Store the content received from the notification so it // can be retrieved from the UI. RawNotification notification = (RawNotification)taskInstance.TriggerDetails; settings.Values[taskName] = notification.Content; } }}

Page 29: Local, scheduled, periodic and push updates.

Capability summary for notifications

Notification type Cycling Scheduled Expiring Recurring Audio Periodic Push

Tile ✔ ✔ ✔ ✔ ✔

Badge ✔✔

Toast ✔ ✔ ✔ ✔ ✔

Raw ✔

Page 30: Local, scheduled, periodic and push updates.

www.buildwindows.com

When should I update my tile or toast?Personalized, real-time status Push

e.g. a friend achieves a new high score within a game we share

e.g. comments on my photo

Subscribed tailored content updates Pushe.g. ongoing sporting event scores e.g. breaking news

Application launch/usage Local / Push

e.g. update app tile to match more recent app content

e.g. clearing the unread mail count when mail is opened

Periodically for non-personalized content Periodice.g. every 30 minutes for stock or weather updates

Missed toast notifications Local / Push

e.g. missed phone calls in a VOIP app

Page 31: Local, scheduled, periodic and push updates.

www.buildwindows.com

How should I not update my tile?Avoid high frequency, streaming updatese.g. every minute to report a play-by-play sporting event e.g. real-time stock ticker on the tile

Do not clear the tile when the app launches/exitsLeave content on the tile to draw your user back to the app.It is okay to update the tile on app exit, however.

Do not update to explicitly replace ‘old content’Set the optional expiration on the tile at the time it is sent.

Only send new updates if there is new data to show the user.

Do not depend on tile orderingNotification queue tile display order is not guaranteed – “storyboards” will not work on tiles. Tile updates must be independent of one another.

Page 32: Local, scheduled, periodic and push updates.

• 11/1 4:15pm - Baker – Windows 8 Connectathon with Windows Azure Mobile Services (3-129)

Related sessions

Page 35: Local, scheduled, periodic and push updates.

© 2012 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.