How to send notification to device without server configuration.

This article is another milestone article for the push notification series. This article is going to explain how to send push notification without server configuration. But keep in mind these steps only can be used for testing purposes, If your system is going to prepare for a production-level launch you must have the server configurations.

Send push notification without backend

We are going to use one of the open-source applications available from GitHub which is supporting both P12 and P8 certificates.

Hold On ✋, Before installing this app and sending a push notification you should have a P8 token or P12 certificate. If you don’t know how to get the P12 or P8 certificate and what is it, please checkout my other article that explains step by step.

Step 1

From this GitHub page, we can download the dmg file from their release page. Download the latest version dmg file and install the app on your mac.

Download dmg file from release page
App looks once install the app from GitHub

Step 2

After installing the app, select the iOS on the top selection then if you are using the certificate option as

P12 Certificate

Select the P12 button on top and upload your P12 certificate (with password if you give the password when you export the P12 certificate) which you download from the previous article.

Enter your project Bundle Id and Device Token, which you created in 2nd part of push notification series article.

Then enter JSON object as in the picutre and select the sandbox environment click the send button

Send push notification using Push Notifications Tester app

FYI, For me I left the password as empty when create the P12 certificate.

P8 Token

In the previous article, you have already downloaded the P8 file from the App Store connect. In this section we are going to use that P8 file, 10-character Key ID and Team Id (which can get from the Developer Account)

If you still don’t know how to get the P8 token, please checkout my other article.

Select the iOS app on the top button and then select the Token option instead of Certificate.

Then upload the file you downloaded in the previous article and enter the 10-character Key ID and your team identifier from the developer account.

Add the push message as in the picture above and select the sandbox environment and click the send button

Step 3

Before clicking the Send button from the previous step, close the app or put the app in the background. Once you hit the send button you should be able to see a push message in your sample App 😃

push notification received on mobile

But why should I put the app to the background or close the app to get the push notification? Can’t I be able to receive the notification when the app is running on foreground?

Actually you can receive push notification when the app in the foreground too. In order to receive the notification, you should add a one UserNotification delegate function in your AppDelegate. Go the the AppDelegate class and inside the didFinishLaunchingWithOptions register the UNUserNotificationCenter delegate.

Register delegate in the didFinishLaunchingWithOptions

Next add a extension for the AppDelegate with UNUserNotificationCenterDelegate and add a function called userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

Register foreground receive notification

Based on this logic I’m giving the completion handler as play the sound and present push notification. After you added this logic, run the app on your real device and send the push notification using Push Notifications Tester app. You should be able to now receive the notification even the app is in the foreground mode.

Receive push notification when the app in Foreground

Conclusion

We came to the end of this article, and finally, we were able to see the push notification in our app. What’s the next step, in the next article of this push notification series going to cover how can we test the push notification in Simulator.

Hope you guys learn new stuff through this article, give some claps 👏 and boost me to write more articles. If you feel anything I can improve or any questions you have feel free to add them to the comments section.

Check out the latest code from GitHub

See you in the next article…..
Happy coding 😃

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store