azure notification hub

26
Azure Notification Hub Luca Di Fino [email protected] @luke2375 luke2375.wordpress.com MICROSOFT MOBILE CAMP ROMA, 12 Febbraio 2015

Upload: luca-di-fino

Post on 30-Jul-2015

219 views

Category:

Software


5 download

TRANSCRIPT

Page 1: Azure Notification hub

Azure Notification Hub

Luca Di Fino

[email protected]

@luke2375

luke2375.wordpress.com

MICROSOFT MOBILE CAMPROMA, 12 Febbraio 2015

Page 2: Azure Notification hub

Agenda

• Overview• Azure Notification Hub• Let’s start• Hub• App• Push

• Something more• More notifications• More channels• More apps

• Q&AMOBILE CAMPROMA, 12 Febbraio 2015

Page 3: Azure Notification hub

3

Overview• Push Notifications offer developers a way

to send timely information relating to their applications even when they are not running • Push notifications are delivered through

platform-specific infrastructures called Platform Notification Systems (PNS)+Windows has the unique ability to

provide the end user glanceable access to the information they care most about, via Live Tiles

MOBILE CAMPROMA, 12 Febbraio 2015

Back-end

PNS

Device

1

2

3

4

Retrieve PNS Handle

Store PNS Handle

Send Notification

Send to Device

Page 4: Azure Notification hub

Critical points• Users management• Platform dependency• Scale• Refresh handles• Multicast

• Routing• Monitor and

telemetry

MOBILE CAMPROMA, 12 Febbraio 2015

4

Page 5: Azure Notification hub

5

A lot of time spent in topics unrelated to the main business logic of the app !!!

MOBILE CAMPROMA, 12 Febbraio 2015

Page 6: Azure Notification hub

Azure Notification Hub

MOBILE CAMPROMA, 12 Febbraio 2015

6

Page 7: Azure Notification hub

Azure Notification Hub

• Device token management• Multiple platforms• Scale• Works with any backend• .NET, Node.JS, REST API, PHP, Java, etc.

• Efficient tag-based multicast and pub/sub routing• Personalization• Rich telemetry

MOBILE CAMPROMA, 12 Febbraio 2015

Page 8: Azure Notification hub

8

MOBILE CAMPROMA, 12 Febbraio 2015

With Azure’s Notification Hub1 million push notifications/month are

free

Page 9: Azure Notification hub

Demo

MOBILE CAMPROMA, 12 Febbraio 2015

9

+

Page 10: Azure Notification hub

Demo walk-through

1. Create the notification hub – Azure2. Get app SID and Secret – Dev Center (Windows or Windows Phone)3. Configure hub

4. Create client app – Visual Studio5. Create app backend

MOBILE CAMPROMA, 12 Febbraio 2015

Page 11: Azure Notification hub

11

Create the Notification Hub

MOBILE CAMPROMA, 12 Febbraio 2015

Page 12: Azure Notification hub

12

Get app SID and Secret (Windows)

MOBILE CAMPROMA, 12 Febbraio 2015

1

2

Page 13: Azure Notification hub

13

Get app SID and Secret (Windows Phone)

MOBILE CAMPROMA, 12 Febbraio 2015

1

2

Page 14: Azure Notification hub

14

Get app SID and Secret

MOBILE CAMPROMA, 12 Febbraio 2015

SID

Secret

Page 15: Azure Notification hub

15

Configure the Notification Hub

MOBILE CAMPROMA, 12 Febbraio 2015

Page 16: Azure Notification hub

16

Configure the app (WinRT)

MOBILE CAMPROMA, 12 Febbraio 2015

string notificationHubPath = NOME_HUB;string connectionString = DefaultListenSharedAccessSignature;

hub = new NotificationHub(notificationHubPath, connectionString);var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();await hub.RegisterNativeAsync(channel.Uri);

• Add Nuget package WindowsAzure.Messaging.Managed• Set Toast capable in .appxmanifest

• Create and register Notification Channel in app.xaml.cs

Page 17: Azure Notification hub

17

Configure the backend

• Add Nuget package WindowsAzure.ServiceBus• Create the hub

• Send native notifications

MOBILE CAMPROMA, 12 Febbraio 2015

private NotificationHubClient hub; hub = NotificationHubClient.CreateClientFromConnectionString(endpoint, hubname);

await hub.SendWindowsNativeNotificationAsync(XMLpayload); //WinRTawait hub.SendMpnsNativeNotificationAsync(XMLpayolad); //Silverlightawait hub.SendAppleNativeNotificationAsync(JSONpayload); //iOSawait hub.SendGcmNativeNotificationAsync(JSONpayload); //Android

Page 18: Azure Notification hub

18

More notifications (toast)

MOBILE CAMPROMA, 12 Febbraio 2015

ToastText01 ToastImageAndText01

Page 19: Azure Notification hub

19

More notifications (tile)

MOBILE CAMPROMA, 12 Febbraio 2015

TileSquareImage/TileSquare150x150Image TileSquarePeekImageAndText02

Page 20: Azure Notification hub

20

More channels

• What if we want more granular control over notifications?• If we want to push notifications only to people who are subscribed to

a specific category, we use tags.App

Backend

Combine tags with AND (&&), OR (||), NOT (!) and parentheses. Tag expressions are limited to 20 tags if they contain only ORs; otherwise they are limited to 6 tagsMOBILE CAMPROMA, 12 Febbraio 2015

string[] tagsToSubscribeTo = { "phone", "news" };await hub.RegisterNativeAsync(channel.Uri, tagsToSubscribeTo);

await hub.SendWindowsNativeNotificationAsync(toast, "phone");await hub.SendWindowsNativeNotificationAsync(toast, "phone && news");await hub.SendWindowsNativeNotificationAsync(toast, "phone || news");

Page 21: Azure Notification hub

21

Schedule notifications

• When in Standard tier, Notification Hubs supports a feature that enables you to schedule notifications up to 7 days in the future

• To cancel a scheduled notification

There are no limits on the number of scheduled notifications you can send

MOBILE CAMPROMA, 12 Febbraio 2015

Notification notification = new AppleNotification("{\"aps\":{\"alert\":\"Happy birthday!\"}}"); var scheduled = await hub.ScheduleNotificationAsync(notification, new DateTime(2014, 7, 19, 0, 0, 0));

await hub.CancelNotificationAsync(scheduled.ScheduledNotificationId);

Page 22: Azure Notification hub

22

Be polite! Let users disable notifications.

Or they will uninstall the app ;-)

MOBILE CAMPROMA, 12 Febbraio 2015

Page 23: Azure Notification hub

23

Unregister notifications

MOBILE CAMPROMA, 12 Febbraio 2015

var registration = await hub.RegisterNativeAsync(channel.Uri, tagsToSubscribeTo);

await hub.UnregisterAsync(registration);

await hub.UnregisterNativeAsync();

await hub.UnregisterAllAsync(channel.Uri);

Page 25: Azure Notification hub

25

Microsoft Virtual Academy

MOBILE CAMPROMA, 12 Febbraio 2015

Page 26: Azure Notification hub

Q&A

MOBILE CAMPROMA, 12 Febbraio 2015

26

Feedback form