26
Mobile Push Notifications to any device with Azure Notification Hubs Sara Silva & Edgar Clérigo

Mobile Notification for any device using Azure Notification Hubs

Embed Size (px)

DESCRIPTION

The talk I did in Microsoft Refresh about Notitification Hubs.

Citation preview

Page 1: Mobile Notification for any device using Azure Notification Hubs

Mobile Push Notifications to any device with Azure Notification Hubs

Sara Silva & Edgar Clérigo

Page 2: Mobile Notification for any device using Azure Notification Hubs

Sara Silva | Edgar Clérigo@saramgsilva @clerigo

IOS DeveloperWindows & Windows Phone DeveloperC#/XAML

Page 3: Mobile Notification for any device using Azure Notification Hubs

Agenda

• Introduction• Using Notification Hubs• Send targeted notifications• How to manage devices from your back-end• Using Templates• Conclusion• Q&A

Page 4: Mobile Notification for any device using Azure Notification Hubs

Push notifications are essential in all apps

For enterprise appsKeep users up to date

Not only for alerts‘push to sync’ notifications

For consumer appsRicher than SMS10000s times cheaper

Page 5: Mobile Notification for any device using Azure Notification Hubs

Mobile push is everywhere

Reservation changes, Deals, Back-officeTravel/Hospitality/Airlines

SMS replacement, Deals, Back-officeBanking/Insurance

Orders, Product UX,Back-officeDiscrete manufacturing/Auto

Prescriptions, Appointments,LOB (maintenance)Healthcare

Breaking newsNews/Media

Offers, Orders, Back-officeRetail

Page 6: Mobile Notification for any device using Azure Notification Hubs

Push notification lifecycle

Registration at app launch1. Client app contacts Platform Notification Service, to retrieve current channel (e.g. ChannelURIs,

device tokens, registrationIds)2. App updates handle in back-end

Sending Notification3. App back-end send notification to PNS4. PNS pushes the notification to the app on the device

Maintenance5. Delete expired handles when PNS rejects them

PlatformNotification

Service

App back-end

Page 7: Mobile Notification for any device using Azure Notification Hubs

Challenges of push notifications

Platform dependency– Different communication protocols to PNS’ (e.g. HTTP vs TCP, xml payload vs json payload)– Different presentation formats and capabilities (tiles vs toasts vs badges)

Routing– PNS’ provide a way to send a message to a device/channel– Usually notifications are targeted at users or interest groups (e.g. employees assigned to a customer account)– App back-end has to maintain a registry associating device handles to interest groups/users

Scale– App back-end has to store current handles for each device high storage and VM costs– Broadcast to millions of devices with low latency requires parallelization (DB and VM)

Page 8: Mobile Notification for any device using Azure Notification Hubs

Using Notification Hubs

One-time set up1. Create a Notification Hub

Register2. The client app retrieves its current handle from the PNS3. Client app creates (or updates) a registration on the Notification Hub with

the current handle

Send Notification4. The app back-end sends a message to the Notification Hub5. Notification Hub pushes it to the PNS’

APNsWNS

Notification Hub

App back-end

iOS app Windows app

MPNS

GCM

ADM

Page 9: Mobile Notification for any device using Azure Notification Hubs

Advantages of using Notification Hubs

X-plat: from any back-end to any mobile platform• Backend can be on-prem or in the cloud, .NET/Node/Java/PHP/Node/anything. • Support Windows Phone/Windows/iOS/Android and Kindle Fire.

No need to store device information in the app back-end• Notification Hub maintains the registry of devices and the associations to users/interest groups

Routing and interest groups• Target individual users and large interest groups using tags

Personalization and localization• Keep your back-end free of presentation concerns like localization and user preferences using templates

Broadcast at scale, multicast, unicast• Push notifications to millions of devices (across platforms) with a single call

Telemetry• Rich telemetry available through portal or APIs

Page 10: Mobile Notification for any device using Azure Notification Hubs

Case studies

Bing (news, finance, sports, …) Sochi 2014

Preinstalled on windows Millions of devices

Millions of notifications/day Minutes to delivery

Interest groups(countries, disciplines, athletes)

Localized notifications

Million devices(iOS, Android, WP) Million notifications

10s

3+ <2

100s

3+ 150+

Page 11: Mobile Notification for any device using Azure Notification Hubs

What’s new

• Kindle support• Tag Expressions• Visual Studio integration• Mobile Services integration• New pricing (completely push-based)• Bulk registration mgmt APIs (private preview)

Page 12: Mobile Notification for any device using Azure Notification Hubs

demoRegister devices in Notification Hubs

WP8.1, Android and IOS

Page 13: Mobile Notification for any device using Azure Notification Hubs

Tags

Tags as interest groups1. Client app can register with a set of tags2. Tags are simple strings (no pre-provisioning is required)3. App back-end can target all clients with the same tag

You can use tags also for• Multiple type of interest groups, e.g.• Follow bands: tag “followband:Beatles”• Follow users: tag “followuser:Alice”

• Tag devices with a user id

Notification Hub

App back-end

Tag:”Beatles”Tag:”Wailers”

Tag:”Beatles”

Page 14: Mobile Notification for any device using Azure Notification Hubs

“How do I read tags from my hub?”

Notification Hubs is not a storage systemMaintain an authoritative store for your tags

In the deviceEvery platform provides apps a way to store user information locally or in the cloudE.g. Roaming settings, iCloud

In your app back-endUsually stored by userTry not to replicate device information

Register methods always overwrite tagsEach time you update the channel, overwrite all the tags

Page 15: Mobile Notification for any device using Azure Notification Hubs

demoUsing tags

WP8.1, Android and IOS

Page 16: Mobile Notification for any device using Azure Notification Hubs

Tag expressions

Social “All my group except me”group:id && !user:id

Events Touchdown event is send to everybody following either teamFollowteam:A || Followteam:B || followplayer:1 || followplayer:2 …

Hours Send notifications at specific times. E.g. Tag with timezone, @12pm in Seattle send:timezone:PST && follows:thaifood

Versions & platforms Send a reminder to update to your first Android app version:version:1.0 && platform:Android

Page 17: Mobile Notification for any device using Azure Notification Hubs

When to register from your app back-end

When tags have to be securedWhen devices register, they can register for any tagSometimes tags have to secure (e.g. using ‘{userId}’ as tag)App back-end can authenticate the user before registering the device

When back-end has to modify tagsTags change as a result of:• Actions on different devices (e.g. adding a tag from the web app)• Other user’s actions (e.g. a manager adding an employee to a work group)Tags are derived from analytics or other user data

Page 18: Mobile Notification for any device using Azure Notification Hubs

Registering from the back-end

Identify your device1. Cannot use ChannelURIs/device tokens/…2. Keep long-living NH registration ids in device storage

Register3. First time only,

a) Request registration id from hub, andb) Store it on device storage

4. CreateOrUpdate device registration (@ every app start)5. Back-end can verify and/or add tags (e.g. performing auth)

Notes6. Nothing is stored in the app back-end7. Do not use device SDK

(risk: multiple registrations for each device)

Notification HubApp back-

end

{id}

upsert({id}, channel, tags)

createId()

Page 19: Mobile Notification for any device using Azure Notification Hubs

Back-end driven tag updates

Use a tag to identify user1. Back-end usually refers to users and not devices2. Register devices with a tag like ‘userid:{id}’

Back-end updates tags3. Retrieve device registration(s) by userid4. Update tags

Note5. No device information in app back-end6. Back-end only refers to users

Notification HubApp back-

end

getByTag(userid)

update(tags)

Page 20: Mobile Notification for any device using Azure Notification Hubs

demoUsing backend for register devices

WebApi and WP8.1

Page 21: Mobile Notification for any device using Azure Notification Hubs

Using templates for multi-platform push

Registration• Client apps can register with a platform specific template, e.g. • Windows tablet registers with Windows Store ToastText01 template• iPhone with the Apple JSON template:

{ aps: {alert: “$(message)”}}

Send notification• App back-end sends a platform independent message: {message:

“Hello!”}

Notes• Multiple templates can be specified for each device• Each template can have a different set of tags

Notification HubApp back-

end

<toast><visual><binding

template=\"ToastText01\"><text

id=\"1\">$(message)</text></binding>

</visual></toast>

{aps: {

alert: “$(message)”

}}

{message:

“Hello!”}

Hello!

Hello

!

Page 22: Mobile Notification for any device using Azure Notification Hubs

Using templates for localization

Registration• Client apps can register with personalized templates, e.g. • Windows tablet wants to receive news in English• iPhone wants Italian

Send notification• App back-end sends a message including both languages: {news_en: “Hello!”, news_it:

“Ciao!”}

Template Expressions• Templates support a simple expression language:• E.g. {‘Sara, ’+$(friend)+’ added you to ’+$(groupName)}

Notification Hub

App back-end

<toast><visual><binding

template=\"ToastText01\"><text

id=\"1\">$(news_en)</text></binding>

</visual></toast>

{aps: {

alert: “$(news_it)”

}}

{news_en:

“Hello!”,news_it:

“Ciao!”}

Hello!

Ciao!

Page 23: Mobile Notification for any device using Azure Notification Hubs

Conclusion

• Notification Hubs Apis are very simple and easy to use in each target;• Tags helps to create interesting groups;• Using WebApi was easy to manage the devices registration and

associate with tags and templates;• Notification Hubs Free is great for test and some apps;• Creating Apple certificates was a bit complicate (for the first time!)• Is not possible to use IOS Simulator for the tests, is needed real device;• Using Android Simulator was a bit complicate because is a requirement

to have Goolge Apis and an account logged.

Page 24: Mobile Notification for any device using Azure Notification Hubs

Q&A?

Page 26: Mobile Notification for any device using Azure Notification Hubs

Thank you!