Reader small image

You're reading from  Hands-On Azure for Developers

Product typeBook
Published inNov 2018
PublisherPackt
ISBN-139781789340624
Edition1st Edition
Tools
Right arrow
Author (1)
Kamil Mrzygłód
Kamil Mrzygłód
author image
Kamil Mrzygłód

Kamil Mrzygłód is a technical lead and technology advisor, working with multiple companies on designing and implementing Azure-based systems and platforms. He's a former Microsoft Azure Microsoft Most Valuable Professional (MVP) and certified trainer, who shares his knowledge via various channels, including conference speeches and open source projects and contributions. Kamil lives in Poland with his two cats and one dog, dedicating some of his time to video games, cooking, and traveling.
Read more about Kamil Mrzygłód

Right arrow

Mobile Notifications with Notification Hub

Push notifications are one of the main features of many mobile apps. They facilitate informing a user about a wait for action, or maybe about a temporary discount that is available only for minutes within an application. While each mobile OS vendor has its own service for such notifications, it's always nice to configure such a feature in one place, so we don't have to worry about changes in the underlying API or the parameters required. Azure Notification Hub simplifies things greatly by providing a single service that acts as a single endpoint for our mobile applications, easing both development and testing.

The following topics will be covered in this chapter:

  • Notification Hub and its benefits
  • Notification architecture and the best patterns for sending a notification to mobile apps
  • Registering a device within Notification...

Technical requirements

To perform exercises from this chapter, you will need the following:

  • An active Azure subscription
  • Visual Studio 2017 with Tools for Universal Windows apps installed
  • A Windows Store account

Reasons to use Notification Hub

If you have ever had a chance to develop an application that was integrated with any notifications system, you probably know the challenges that are faced when creating such a product. In this chapter, I will try to introduce you to some basic concepts such as PNS, push notifications, and device registrations. This will ensure that we can easily start developing applications leveraging Notification Hub features and focus on learning details and hidden functionalities.

Exercises from this chapter are written for Universal Windows Platform (UWP) applications—however, the concepts presented are true also for other platforms such as Android or iOS.

Challenges for application design

Let&apos...

Push notification architecture

Creating a whole system that relies on push notification is not a trivial task. Besides ensuring that you are not focusing on handling each PNS logic individually and providing reliable device registration and routing systems, you have to introduce a pipeline for passing messages from one part of your system to the end device. In this section, we will focus on incorporating Notification Hub into a few reference architectures, which will help you understand its role and the connections between different cloud services.

Direct connection

The simplest architecture we could think of would be a direct connection between a backend and notification service:

In such a scenario, each send notification...

Registering devices in Notification Hub

To be able to actually send a notification, you have to register a device in the PNS. Without using a service such as Notification Hub, you would have to know the individual logic of each PNS and storage device data somewhere. Such a challenge would be problematic in most cases, as usually you do not want to handle external dependencies by yourself; rather, your aim is to simplify the overall system logic. In this section, you will learn how device registration is handled in Notification Hub and how to monitor it.

Notification Hub device registration

When you register a device in Notification Hub, you are actually associating it with a template of a notification and tag. To create such...

Sending a notification

The main functionality of Notification Hub is to send a notification to a set of registered devices. You will see that, using its SDK and portal, you can easily start using that feature without knowing the internal logic of different PNSes. After this section, you should be able to use Notification Hub without problems and incorporate it into your applications.

Sending a test notification

While developing your application, you always need a way to test it. When using Notification Hub, you have two options when it comes to sending a test notification—either use the portal or its SDK. Both possibilities allow for similar results; however, using the SDK is a bit more flexible as it is easier to find...

Rich content notifications

In the last section of this chapter, we will talk a bit about another type of notification, which is called rich content notification. Sometimes you would like to send something more than plain text. In Notification Hub, it is possible to send, for example, an image to enhance the look and feel of an application.

Please note that receiving rich content notifications requires making changes on the client side. We will not cover that in this chapter but, at the end of it, you will find a link where such an operation is described in detail.

Creating and sending a rich content notification

To create and send a rich content notification, you will need two things:

  • A model of a notification
  • The notification...

Summary

In this chapter, you have learned what Notification Hub is and how you can use it to incorporate push notifications into your applications. We covered some reference architectures and possible scenarios, which should help you understand what the purpose of this service is and how it solves problems when sending notifications to multiple PNSes and devices.

This chapter ends the first part of this book. In the next one, we will focus on serverless components and architectures.

Questions

  1. What is PNS?
  2. Do multiple platforms (iOS, Android, and Windows) have different PNSes?
  3. What is the difference between registration and installation?
  4. Can you register the same number of devices in the Free and Basic tiers?
  1. What is the easiest way to check registered devices in Notification Hub?
  2. How can you send a test notification?
  3. What are rich content notifications?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Azure for Developers
Published in: Nov 2018Publisher: PacktISBN-13: 9781789340624
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Kamil Mrzygłód

Kamil Mrzygłód is a technical lead and technology advisor, working with multiple companies on designing and implementing Azure-based systems and platforms. He's a former Microsoft Azure Microsoft Most Valuable Professional (MVP) and certified trainer, who shares his knowledge via various channels, including conference speeches and open source projects and contributions. Kamil lives in Poland with his two cats and one dog, dedicating some of his time to video games, cooking, and traveling.
Read more about Kamil Mrzygłód