azure notification hub
TRANSCRIPT
Azure Notification Hub
Luca Di Fino
@luke2375
luke2375.wordpress.com
MICROSOFT MOBILE CAMPROMA, 12 Febbraio 2015
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
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
Critical points• Users management• Platform dependency• Scale• Refresh handles• Multicast
• Routing• Monitor and
telemetry
MOBILE CAMPROMA, 12 Febbraio 2015
4
5
A lot of time spent in topics unrelated to the main business logic of the app !!!
MOBILE CAMPROMA, 12 Febbraio 2015
Azure Notification Hub
MOBILE CAMPROMA, 12 Febbraio 2015
6
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
8
MOBILE CAMPROMA, 12 Febbraio 2015
With Azure’s Notification Hub1 million push notifications/month are
free
Demo
MOBILE CAMPROMA, 12 Febbraio 2015
9
+
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
11
Create the Notification Hub
MOBILE CAMPROMA, 12 Febbraio 2015
12
Get app SID and Secret (Windows)
MOBILE CAMPROMA, 12 Febbraio 2015
1
2
13
Get app SID and Secret (Windows Phone)
MOBILE CAMPROMA, 12 Febbraio 2015
1
2
14
Get app SID and Secret
MOBILE CAMPROMA, 12 Febbraio 2015
SID
Secret
15
Configure the Notification Hub
MOBILE CAMPROMA, 12 Febbraio 2015
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
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
18
More notifications (toast)
MOBILE CAMPROMA, 12 Febbraio 2015
ToastText01 ToastImageAndText01
19
More notifications (tile)
MOBILE CAMPROMA, 12 Febbraio 2015
TileSquareImage/TileSquare150x150Image TileSquarePeekImageAndText02
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");
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);
22
Be polite! Let users disable notifications.
Or they will uninstall the app ;-)
MOBILE CAMPROMA, 12 Febbraio 2015
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);
24
ResourcesNotification Hub• Azure
• MSDN
• Windows Store (WinRT) tutorial
• Windows Phone (Silverlight) tutorial
• Android tutorial
• iOS tutorial
• Kindle tutorial
Windows toast and tile template catalogs• Toast template catalog
• Tile template catalog
MOBILE CAMPROMA, 12 Febbraio 2015
25
Microsoft Virtual Academy
MOBILE CAMPROMA, 12 Febbraio 2015
Q&A
MOBILE CAMPROMA, 12 Febbraio 2015
26
Feedback form