sending push notifications using the windows push notification service and windows azure

39
Sending Push Notifications to Windows 8 and Windows Phone 7 devices using Windows Azure @cloudnick http://www.nickharris.net Nick Harri s

Upload: microsoft-developer-network-msdn-belgium-and-luxembourg

Post on 30-Jun-2015

2.204 views

Category:

Technology


1 download

DESCRIPTION

More info on http://www.techdays.be.

TRANSCRIPT

Page 1: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Sending Push Notifications to Windows 8 and Windows Phone 7 devices using Windows Azure

@cloudnickhttp://www.nickharris.net

Nick Harris

Page 2: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Session Contents

Review of Live Tiles

A deep dive on using the Windows Push Notification Service

Introduction to the Windows Azure Toolkit for Windows 8 / Windows Phone 7

You’ll leave with examples of how toEnable push notifications in your applicationsBuild a push service using Windows Azure

Page 3: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Demo

Page 4: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Windows 8 Live Tiles with Push Notifications

Page 5: Sending Push Notifications using the Windows Push Notification Service and Windows Azure
Page 6: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Windows Push Notification Service (WNS)

Page 7: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Push Notification Overview1. Request Channel URI

2. Register with your Cloud Service

3. Authenticate & Push Notification

Windows 8

(1)

(2)

(3)

(3)

Page 8: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

1. Request a Channel URIEach tile has a unique Channel URI

Requested by App on each run. URI can change

Generated by WNS

Opaque to the app

Windows 8

(1)

(2)

(3)

(3)

Page 9: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

var push = Windows.Networking.PushNotifications;

var promise = push.PushNotificationChannelManager

.createPushNotificationChannelForApplicationAsync();

promise.then(function (ch) {

var uri = ch.uri;

var expiry = ch.expirationTime;

updateChannelUri(uri, expiry);

});

Page 10: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

2. Register with Your Cloud Service Register your app with

your own Cloud ServiceShould be authenticated and secure

Store Channel URI and associate it with any app specific context

Create your business logic for sending notifications

Windows 8

(1)

(2)

Page 11: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

function updateChannelUri(channel, channelExpiration) {

if (channel) {

var serverUrl = "https://mysampleapp.cloudapp.net/register";

var payload = { Expiry: channelExpiration.toString(),

URI: channel };

var xhr = new WinJS.xhr({

type: "POST",

url: serverUrl,

headers: { "Content-Type": "application/json; charset=utf-8" },

data: JSON.stringify(payload)

}).then(function (req) { … });

}

}

Page 12: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Authenticate & Send Notification

OAuth 2 Authentication

HTTP POST to Channel URI

XML notification payload

Windows 8

(2)

(3)

(3)

Page 13: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Register Your App

Page 14: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

POST https://login.live.com/accesstoken.srf HTTP/1.1Content-Type: application/x-www-form-urlencodedHost: login.live.comContent-Length: 221

grant_type=client_credentials&client_id=ms-app%3A%2F%2FS-1-15-2-1633617344-1232597856-4562071667-7893084900-2692585271-282905334-531217761&client_secret=XEvTg3USjIpvdWLBFcv44sJHRKcid43QXWfNx3YiJ4g&scope=notify.windows.com

Page 15: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

HTTP/1.1 200 OKCache-Control: no-storeContent-Length: 422Content-Type: application/jsonConnection: close{

"access_token":"EgAcAQMAAAAg/RBw++jdA1MzM0LTUzMTIxNzc2MQA=", "token_type":"bearer“

}

Page 16: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Push Notification HTTP Request

POST https://db3.notify.windows.com/?token=AQI8iP%2OtQE%3d HTTP/1.1Content-Type: text/xmlHost: db3.notify.windows.comX-WNS-Type: wns/badgeAuthorization: Bearer EgAcAQMAAAAg/RBw++jdA1MzM0LTUzMTIxNzc2MQA=Content-Length: 58

<?xml version="1.0" encoding="utf-8"?><badge value="34"/>

Page 17: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Push Notification HTTP Response

HTTP/1.1 200 OKContent-Length: 0X-WNS-NOTIFICATIONSTATUS: receivedX-WNS-MSG-ID: 1ACD59E4683FE4BFX-WNS-DEBUG-TRACE: DB3WNS4011434

Important NotesDevice can be offline or disconnected. Success indicates that the request was successfully received by WNS; not necessarily that the user saw it.Additional headers in the response for notification and device status.

Page 18: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Announcing

Page 19: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Authentication Code

using Windows.Recipes.Push.Notifications.Security;…// Constructor takes your Package SID and secret keyIAccessTokenProvider _tokenProvider = new WNSAccessTokenProvider(

"ms-app%3A%2F%2FS-1-15-2-1633617344-1232597856-4562071667-7893084900-2692585271-282905334-531217761",

"XEvTg3USjIpvdWLBFcv44sJHRKcid43QXWfNx3YiJ4g");

Page 20: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

3. Push Notification Code

using Windows.Recipes.Push.Notifications;

var toast = new ToastNotification(_tokenProvider);toast.ChannelUrl = "https://db3.notify.windows.com/?token=AQI8iP%2OtQE%3d";

toast.ToastType = ToastType.ToastImageAndText02;

toast.Image = "https://demosa.blob.core.windows.net/toastImg1.png";

toast.Text = new List<string> {"Miguel Saenz comment on your status", "I love that quote! How have you …"};

NotificationSendResult result = toast.Send();

Page 21: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Push Notification Summary1. Request Channel URI

2. Register with your Cloud Service

3. Authenticate & Push Notification

Windows 8

(1)

(2)

(3)

(3)

Page 22: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

What a service needs to support

How do I do that with Windows Azure?

Page 23: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Demo

Page 24: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Push Notifications

Windows Phone 7

Page 25: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

WP7 ToastTitle. A boldface string that displays immediately after the application icon. This is defined as the Text1 property in the XML schema.

Content. A non-boldface string that displays immediately after the Title. This is defined as the Text2 property in the XML schema.

Parameter. A parameter value that is not displayed but passed to your application if the user taps on the toast. This parameter can indicate what page the application should launch to. It can also contain name-value pairs to pass to the application. This is defined as the Param property in the XML schema

Page 26: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

WP7 Tile - FrontTitle. A string indicating the title of the application. The Title must fit on a single line of text and should not be wider than the actual Tile. Approximately 15 characters will fit in the title before being truncated.

BackgroundImage. An image displayed on the front of the Tile. We recommend that you always have a background image on the front of the Tile.

Count (also known as Badge). An integer value from 1 to 99. If the value of Count is not set or it is set to 0, the circle image and value will not display in the Tile.

Page 27: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

WP7 Tile - BackBackTitle. A string displayed at the bottom of the back of a Tile. The BackTitle must fit on a single line of text and should not be wider than the actual Tile. Approximately 15 characters will fit in the title before being truncated.

BackBackgroundImage. An image displayed on the back of the Tile.

BackContent. A string displayed in the body of the back of a Tile. Approximately 40 characters will fit in the Tile before being truncated.

Page 28: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

WP7 Raw• Push data to your application

• If app is not currently running MPNS discards the message.

• Watch out for max payload size. If exceeds use to drive app to pull content from service

!Raaawww

Page 29: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Demo

Page 30: Sending Push Notifications using the Windows Push Notification Service and Windows Azure
Page 31: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

src: http://blogs.msdn.com/b/b8/archive/2011/11/02/updating-live-tiles-without-draining-your-battery.aspx

Figure 4: Live tiles registered to the Developer Preview Stocks app

Page 32: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Core Services Services to Help Scale

Page 33: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Summary

Page 34: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

SummaryThere are 3 easy steps to implement push notifications:

The Windows Push Notification Recipe helps you easily add push notifications to your service

The Windows Azure Toolkit for (Windows Phone || Windows 8)is the best way to start building a service

Windows Azure provides the resources to scale your services as your app grows

Page 35: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Get Started

http://WindowsAzure.com

Page 36: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Android

Windows Phone

http://bit.ly/watandroidhttp://bit.ly/watios

http://bit.ly/watwp7

3 Month Free Trial Benefits (Monthly)Subscription Level 3 Month Free Trial

Compute 750 hours of a Small Compute Instance*

Storage 20GB with 50k Storage transactions

SQL Azure 1GB Web Edition SQL Azure database

Access Control Transactions** 100k transactions

Service Bus Free through March 31, 2012

Caching 128 MB cache

Data Transfers (WW) 20GB outbound / Unlimited inbound data transfer

* (can run one small instance full-time or other sizes at their equivalent ratios)

Page 37: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Android

Windows Phone

http://bit.ly/watandroidhttp://bit.ly/watios

http://bit.ly/watwp7

MSDN Subscriber Benefits (Monthly)Subscription Level Visual Studio

Professional with MSDNVisual Studio Premium with MSDN

BizSpark & Visual Studio Ultimate with MSDN

Compute 375 hours of the Small Instance

750 hours of the Small Instance

1,500 hours of the Small Instance

Storage 20 GB 25 GB 30 GB

Storage Transactions

250,000 1,000,000 2,000,000

SQL Azure 1GB 1GB 5GB

Access Control Transactions*

100k 200k 500k

Service Bus Free through March 31, 2012

Free through March 31, 2012

Free through March 31, 2012

Caching 128 MB cache 128 MB cache 128 MB cache

Data Transfers (WW)

25GB OutFree In

30GB OutFree In

35GB OutFree In

Annual Savings** $1,300.00 $2,100.00 $3,700.00 * The Windows Azure Access Control service is provided at no charge for billing periods prior to January 1, 2012.** Projected annual savings at Pay-As-You-Go rates in US dollars.http://www.windowsazure.com/en-us/pricing/member-offers/msdn-benefits/

Page 38: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

Resources

Register your apphttp://manage.dev.live.com/build

Download the Windows Azure Toolkit for Windows 8 http://WATWindows8.codeplex.com

Download the Windows Azure Toolkit for Windows Phone http://WATwp.codeplex.com

Windows 8 Developer Documentationhttp://dev.windows.com

Page 39: Sending Push Notifications using the Windows Push Notification Service and Windows Azure

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