Push Notifications

A push notification (also known as a server push notification) is the delivery of information to a computing device from an application server where the request for the transaction is initiated by the server rather than by an explicit request from the client. While ‘push notification’ is most often used to refer to notifications on mobile devices, web applications also leverage this technology.

Reach Users with Push Notifications

APNS (Apple Push Notification Service ) launched as the first mobile push notification service in 2009. Since then, Google released and iterated on its own push service and Rich Notifications became par for the course on Android and iOS devices. In addition to these advancements, the W3C Push API sets the standard for push notifications from web applications.

Push notifications do not require a particular application to be open on a device for the message to be received by the end user, so a smartphone user can see notifications even when their phone is locked, or an app is not running.The end user must opt-in to receive push notifications from a given application. An application usually makes the opt-in request on its initial installation, and the user may always grant or revoke consent for notifications at any time.

How are Push Notifications Added to an Application?

Each native mobile application platform (iOS, Android, Windows, Fire OS, Blackberry) has its own set of development guidelines and standards, as well as its own OSPNS (Operating System Push Notification Service). Most of these OSPNS allow push notifications to include text, images, app badges, and sounds. The OSPNS routes the notification from the application provider to the application user’s device.

To add push notifications to an application, the application publisher registers with the push notification service of the OS for which they’re developing. Then their OS service provides an API to the app publisher so that the app can communicate with the service. The app publisher then adds the SDK to their application, then uploads the app to the appropriate app store.

What are the Benefits of Push Notifications?

There are several benefits of push notifications:

  • Cost: Mobile users without unlimited texting plans must pay for incoming texts and are likely to quickly opt out of SMS communications, while there is no extra charge to the consumer for a push notification to a mobile phone.
  • User Control: Requiring a user to opt-in for notifications (and always allowing them to opt-out) as well as flexible notification preferences give users control over where and how they receive notifications.
  • Risk Reduction: Push notifications do not conflict with the rules of the TCPA, as these notifications are entirely opt-in/opt-out. Therefore, push notifications may help reduce the risks of harassing users and potential litigation.
  • Engagement: Push notifications increase application engagement and improve retention rates.

What are Push Notifications on Android and iOS?

  • Push notices are straightforward messages conveyed from applications installed on a device.

  • Push notifications are broadly utilized on every single cell phone to share updated information or events.

  • On Android devices, when you get push notifications, the sender application’s symbol and a message show up in the status bar. At the point when the client taps the notification, he/she arrives on the application.

  • Push notification mobile web can be communicated to all clients (the case for marking efforts) or can likewise be sent to only a subset of clients, to share customized data.

  • On iOS, Apple includes a Notification Center, which is arranged in sequential order, and clients get to the Notification Center by swiping down from the top point of the screen. Android gadgets indicate new messages on the lock screen.

  • iOS gives clients a chance to alter push notification web service at an individual application level. Clients can turn sounds on or off, and pick the style that iOS uses to demonstrate a notification.

  • Clients can likewise control the red “Badge” demonstrating the quantity of new notification on an application’s home-screen symbol.

  • Android utilizes a standard banner approach that clients can’t change at an OS level.

What are remote Push Notifications?

Apple Push Notification service (APNs) is the centerpiece of the remote notifications feature. It is a robust, secure, and highly efficient service for app developers to propagate information to iOS (and, indirectly, watchOS), tvOS, and macOS devices.

What can Push Notifications do?

I am going to refer to Push Notifications as Push Notifications, PNs, APNs, Notifications, Remote Push Notifications, Remote Notifications and I will always have the same notion in mind.

Here is what you can do with APNs these days:

  • Display a message.
  • Play a sound.
  • Set a badge icon on your app.
  • Provide actions the user can act upon with or without opening the app.
  • Show an image or other types of media.
  • Be silent but ask the app to perform some action in the background.

However, before seeing any of the APNs magic happen, there is some configuration to be done! It will help us protect our precious remote notifications from possible invaders “robust, secure, and highly efficient”.

Stuff needed to be prepared Before APNS configuration can start

  • A real iOS device. Simulators cannot receive notifications, unfortunately.
  • Apple Developer Program Membership that is right, you need to finally pay what you have been avoiding to.
  • A way to send notification payloads to your device a good way to do that is the simple to install and use Pusher app.

APNS Configuration and initial step-by-step implementation :

  • Step 1, project set-up: Like anything else you are probably learning these days about iOS apps, it all starts with creating a project. That is right, mine is named Unicorn.
  • Step 2, enabling APNs: In Xcode, go to your Targets, under your app’s name, select Capabilities and find Push Notifications in the list, switch to ON: Enable Push Notifications in Capabilities in Xcode

Step 3, get APNs certificate: Go to your Apple Dev Member Center Account and log in. Click Certificates, IDs & Profiles -> Identifiers -> App IDs where you should see all your app identifiers, select the one you are creating the notifications for. You will see a big list of Application Services available — Push Notifications should be marked as configurable:

Push Notifications Configurable

There should be an Edit Button at the bottom, click it and find Push Notifications in that list again:

What you need is the Development SSL Certificate(clarification regarding development vs. productions certificates provided at the end of the article), click on the Create Certificate Button and follow the instructions to create a CSR File. In short, hold CMD + Space to start the spotlight search on your Mac, write Keychain Access, and press enter to launch the Keychain Access App:

Next Apple’s instructions :

Within the Keychain Access drop-down menu, select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority. Keychain Access drop-down on left and Certificate Information window on right Properly fill in the Certificate Information and make sure you save the .certSigningRequest file at an easy-to-find place because then you need to upload it here:

Download .cer file screen
Download the generated Certificate, double-click the .cer file and find it it installed in your Keychain Access.
This step was a long one but worth it. Follow these steps again Certificates, IDs & Profiles -> Identifiers -> App IDs and you should see that Push Notifications are now enabled for Development: Developer Push Notifications enabled

Step 4, some code finally:

Go back to the project and open the AppDelegate.swift file. This is where we are going to ask the user for a permission to receive notifications from us before we try sending some data. On top of your AppDelegate.swift file, first:

import user notifications

Then within the AppDelegate class, add registerForPushNotifications function
It is quite straightforward — we access the instance of the UserNotificationCenter, and then ask it to authorize us to send push notifications to the user in the form of alerts, sounds, and badge app numbers. If granted, we call the registerForRemoteNotifications() function of the shared application instance on the main thread. We need to explicitly do it on the main thread or else, we would get the annoying error saying that we are calling the function on a background thread.

Then we call registerForPushNotifications() function at the end of application(_:didFinishLaunchingWithOptions:) but before the return true statement, like this:
Calling registerForPushNotifications in the proper place.

In that way, we make sure the user is asked to register for push notifications at the start of the application. Run the project to see this:

Notification Authorization within App

As shown in the thread above image alert was displayed with two options i.e., Allow and Don’t Allow. If a user selects Allow then notification was allowed for the app otherwise, notifications not allowed for the app. However, there is a pitfall to bear in mind in general — a user can always disallow push notifications authorization in the phone’s settings. There are two more delegate functions (whose purpose is obvious I believe — one gets us the device token, the other one checks for errors if any) to implement before we see any Push Notification action: Converting the device token or printing out an error code.
The code in the did register … a function may seem weird at first but all it does is stringify the token for us so we can use it within the Pusher App. Step 5, sending a notification finally: Open Pusher after installing it:

Default start-up for Pusher :

There is a drop-down menu where Pusher automatically detects what Push Certificates you already have in your Keychain Access. Click it and pick the one that corresponds to your app.Then push button was enabled, when clicking on the push button, notification is displayed as shown in below image.

Author: Srinivasa Rao Polisetty – iOS Developer
Source: Wikipedia and developer.apple.com

Share This Information