25

Techdays 2012 - Windows Phone Push notifications & Life tiles

Embed Size (px)

DESCRIPTION

Developer presentation on implementing push notifications and life tiles to your Windows Phone applications

Citation preview

Page 1: Techdays 2012 - Windows Phone Push notifications & Life tiles
Page 2: Techdays 2012 - Windows Phone Push notifications & Life tiles

Push notifications, live tiles and background agentsfor Windows Phone 7

Geert van der CruijsenConsultant – Avanade

@geertvdchttp://vdcruijsen.net

Page 3: Techdays 2012 - Windows Phone Push notifications & Life tiles

Make your App come alive with

push notificationsand live tiles

Page 4: Techdays 2012 - Windows Phone Push notifications & Life tiles

Push notificationsTileIf tile is pinned tile will be updatedApplication not accessed

ToastData delivered to app when app is runningToast popup if app is not running

RawOnly delivered when app is runningContent handled by application

Page 5: Techdays 2012 - Windows Phone Push notifications & Life tiles

Architecture

Microsoft Push Notification Server

Cloud App Service

Push Client Service

Push enabled Application

Request push URI

Push client/server negotiation

Register URI at App service

Push message

Push message

Page 6: Techdays 2012 - Windows Phone Push notifications & Life tiles

Even when he’s not using your app

Notifythe user

Page 7: Techdays 2012 - Windows Phone Push notifications & Life tiles

Scenarios

WeatherGamesSportsMessagingNewsUtilities

Page 8: Techdays 2012 - Windows Phone Push notifications & Life tiles

Building the Phone partAsk for user permissionNot being able to disable push notifications will fail marketplace certification

Register Phone with Push Service

Register Event Handlers

Handle optional in app notificationsRaw notifications

In app toast notifications

Page 9: Techdays 2012 - Windows Phone Push notifications & Life tiles

DemoBuilding the Phone Part

Page 10: Techdays 2012 - Windows Phone Push notifications & Life tiles

Building the ServiceRegister PhoneUnique IDURI

Update Phone URI

Send Notifications

Handle return codes

Page 11: Techdays 2012 - Windows Phone Push notifications & Life tiles

DemoBuilding the Service Part

Page 12: Techdays 2012 - Windows Phone Push notifications & Life tiles

Phone APIPinning tiles

ShellTileUpdateprivate void CreateTileSchedule(){ schedule = new ShellTileSchedule(); schedule.Interval = UpdateInterval.EveryDay; schedule.MaxUpdateCount = 7; schedule.Recurrence = UpdateRecurrence.Interval; schedule.RemoteImageUri = new Uri(@"http://www.server.com/image.png"); schedule.Start();}

Page 13: Techdays 2012 - Windows Phone Push notifications & Life tiles

DemoGenerating dynamic local tile images

Page 14: Techdays 2012 - Windows Phone Push notifications & Life tiles

Service XML messagesTile notifications<wp:Notification xmlns:wp="WPNotification">   

<wp:Tile Id="/SessionPage.xaml?id=0">     

<wp:BackgroundImage>http://www.server.com/background.png</wp:BackgroundImage>     

<wp:Count>12</wp:Count>     

<wp:Title>Techdays App</wp:Title>     

<wp:BackBackgroundImage>http://www.server.com/backbackground.png</wp:BackBackgroundImage>     

<wp:BackContent>PushNotification session</wp:BackContent>     

<wp:BackTitle>Geert van der Cruijsen</wp:BackTitle>   

</wp:Tile>

</wp:Notification>

Page 15: Techdays 2012 - Windows Phone Push notifications & Life tiles

Service XML messagesToast notifications<wp:Notification xmlns:wp="WPNotification">   

<wp:Toast>     

<wp:Text1>Techdays2012</wp:Text1>     

<wp:Text2>Next session starts in 5 minutes</wp:Text2>     

<wp:Param>/SessionPage.xaml?id=1</wp:Param>   

</wp:Toast>

</wp:Notification>

Page 16: Techdays 2012 - Windows Phone Push notifications & Life tiles

Tips & TricksUser Opt-in

Check device capabilities<Capability Name="ID_CAP_PUSH_NOTIFICATION"/>       <Capability Name="ID_CAP_IDENTITY_DEVICE"/>

Encrypt channel URI

Tiles max 80kb and 15 seconds

Page 17: Techdays 2012 - Windows Phone Push notifications & Life tiles

Tips & TricksPower managementCriticalLowPowerLevel – No push messages will be sentLowPowerLevel – only Raw push messages will be sentNormalPowerLevel – All push messages will be sent

MPNS http response codes200 OK – Received, Suspended, QueueFull400 Bad Request – Error in your xml404 Not Found – Subscription not valid. Stop sending406 Not acceptable – Maximum of 500 messages reached412 Preconditions failed – Phone inactive. Resend max 1x per hour

Page 18: Techdays 2012 - Windows Phone Push notifications & Life tiles

Background agentsPeriodicTaskRecurring task on regular intervalMax every 30 minutesMaximum of 6 background agents per device

ResourceIntensiveTaskSingle task that can run for a longer time when specific requirements are met

Page 19: Techdays 2012 - Windows Phone Push notifications & Life tiles

PeriodicTaskUnsupported APIsUICamera

Memory restrictions6 MB / 15 MB

Reschedule every 2 weeksUnscheduled after 2 consecutive crashes

Page 20: Techdays 2012 - Windows Phone Push notifications & Life tiles

PeriodicTask Typical APIsGeoCoordinateWatcher

HttpWebRequest

Mutex

ShellToast

ShellTile

Page 21: Techdays 2012 - Windows Phone Push notifications & Life tiles

ResourceIntensiveTaskHeavy requirementsMax duration of 10 minutesExternal power requiredNon cellular internet connection requiredBattery power needs to be 90% or higherScreen needs to be locked

Page 22: Techdays 2012 - Windows Phone Push notifications & Life tiles

DemoBuilding a background agent

Page 23: Techdays 2012 - Windows Phone Push notifications & Life tiles

ResourcesPush Notification Helper Libraryhttp://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx

Azure toolkithttp://watoolkitwp7.codeplex.com/

Windows Phone App hubhttp://create.msdn.com

#wp7nl

Page 24: Techdays 2012 - Windows Phone Push notifications & Life tiles

Call to actionStart building Windows Phone apps!

Include Push notifications and/or live tiles!Multiple local tilesPush is not hard!

Page 25: Techdays 2012 - Windows Phone Push notifications & Life tiles

Q&A

@geertvdchttp://vdcruijsen.net