14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

azure mobile services<br />

Push Notifications in<br />

Windows 8 Apps<br />

Sumit Maitra introduces the Windows Push Notification Service and how to<br />

implement it for Windows 8 Store Apps using Azure Mobile <strong>Services</strong><br />

With the popularity of Smart Phones and<br />

always connected (to internet) devices,<br />

‘push notifications’ have gained immense<br />

popularity. Though push notifications are<br />

not new and Exchange had implemented<br />

Active Sync quite some time back,<br />

smartphones have made them<br />

ubiquitous and brought them out of the<br />

Enterprise-y setups. So today, we often<br />

receive updates instead of looking<br />

(polling) for updates. This can be a more<br />

efficient process depending on the<br />

implementation.<br />

Common examples of Push<br />

notification usage are, mail clients that<br />

receive new mail notifications as they<br />

come to their server’s Inbox. E.g. Social<br />

Media apps that push updates to all<br />

subscribed as soon as someone makes<br />

an update to their status or games that<br />

can push leaderboard updates of your<br />

position changes and so on.<br />

Given the popularity and utility of Push<br />

Notifications, it’s a desired feature to<br />

have in mobile applications. However,<br />

setting up the infrastructure to do so<br />

is non-trivial on any client (Windows<br />

Phone, iOS, Android or Windows 8)<br />

platform. This is where the Windows<br />

Azure Team has stepped in with the<br />

Windows Azure Mobile <strong>Services</strong> that<br />

among other things, aim to ease the<br />

burden of building Push Notification<br />

infrastructure for connected apps.<br />

Today, we will see how to build a<br />

Windows 8 Store App that is capable<br />

of receiving push notifications. For the<br />

backend infrastructure we will use<br />

Windows Azure Mobile <strong>Services</strong>.<br />

Windows (Push)<br />

Notification Service<br />

The underlying infrastructure that enables Push notifications is<br />

referred to as Windows Push Notification Service or WNS for short.<br />

The typical process is as follows:<br />

1. You first get an App SID and Client Secret for your Windows 8<br />

Store App and store it in your <strong>Web</strong> Service.<br />

2. Next your App requests Windows for a ‘Channel’ and sends it to<br />

your <strong>Web</strong>Service so that it can track the channels.<br />

3. When one of the clients submit some data to your web service<br />

that needs to send out push notifications, the web service provides<br />

WNS with the SID and Client secret along with the channel details for<br />

the notification to propagate.<br />

Figure: Relationship between the various components that your app must communicate with, for WNS to work<br />

4. All clients that the data was intended for, then receive the push notification. The clients could be direct recipients or subscribed for by the client<br />

5. Notifications in Windows 8 can be<br />

a. Tile notifications (primary/secondary)<br />

b. Toast notifications (for toast popup)<br />

c. Raw notifications (to download data)<br />

72 | DNCmagazine www.dotnetcurry.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!