Push notifications, live tiles and background agentsfor Windows Phone 7
Geert van der CruijsenConsultant – Avanade
@geertvdchttp://vdcruijsen.net
Make your App come alive with
push notificationsand live 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
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
Even when he’s not using your app
Notifythe user
Scenarios
WeatherGamesSportsMessagingNewsUtilities
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
DemoBuilding the Phone Part
Building the ServiceRegister PhoneUnique IDURI
Update Phone URI
Send Notifications
Handle return codes
DemoBuilding the Service Part
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();}
DemoGenerating dynamic local tile images
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>
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>
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
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
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
PeriodicTaskUnsupported APIsUICamera
Memory restrictions6 MB / 15 MB
Reschedule every 2 weeksUnscheduled after 2 consecutive crashes
PeriodicTask Typical APIsGeoCoordinateWatcher
HttpWebRequest
Mutex
ShellToast
ShellTile
ResourceIntensiveTaskHeavy requirementsMax duration of 10 minutesExternal power requiredNon cellular internet connection requiredBattery power needs to be 90% or higherScreen needs to be locked
DemoBuilding a background agent
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
Call to actionStart building Windows Phone apps!
Include Push notifications and/or live tiles!Multiple local tilesPush is not hard!
Q&A
@geertvdchttp://vdcruijsen.net