Testing Push Notifications in iOS Simulator

Mukesh Shakya
3 min readJun 17, 2021

Push notifications are used by almost all developers to keep their user engaged with their apps. Push notifications are used to present information to users using the app to inform them about something like offers, coupons, news, etc or redirect them to some specific section of the app when clicked in the notification popup.

Until the release of Xcode 11.4, developers were compelled to test push notification functions using their iOS devices. But with the release of Xcode 11.4 apple has added a functionality to test push notifications itself in the simulator. Finally, great news for developers without an iPhone or an iPad.

What do you need to master this tutorial

  • Xcode (latest if possible or at least 11.4)
  • Swift language
  • Prior knowledge of implementation of Push Notification
  • Apple Developer Program Membership (Paid)

Overview

Xcode 11.4 has been released with a feature of testing push notifications in the simulator. Testing push notification in the simulator just needs a local payload file to be dragged on the simulator.

Pre-requisites

Before testing push notifications in your iOS simulator, your app must first be able to support push notification. I won’t be going through those steps so please make your app able to handle normal push notifications, I will be waiting for you right here. Also do not forget to allow your app to receive push notifications when the permission alert prompts. So let’s do that and follow along with me. It won’t be that hard.

Creating an Apple Push Notification Service (APNS) payload file

The APNS payload file is a JSON file that contains information about the push notification.

Now a question may arise that we don’t have to do all this stuff while we are testing push notifications on an iOS device. During testing push notification in iOS devices we generally use a backend service or a firebase console, the payloads are made and sent by the backend service or firebase console at the time. But now we are trying to test our push notification service locally so currently we have to make our hands dirty.

Before creating the payload file, we need to grab the app’s bundle ID from Xcode.

Retrieving target bundle identifier

After we have the bundle id of our target, we can now proceed to create our payload file. Now open your favourite text editor and let us start creating our APNs payload JSON. For the demonstration process we will use a simple payload here.

{    "Simulator Target Bundle" : "com.tutorial.simulatorNotificationTest",    "aps" : {        "alert" : {            "title" : "Testing Push Notification in Simulator",            "subtitle" : "Feature check",            "body" : "A good news for iOS developer without iOS devices 😍"        },        "badge" : 1,        "sound" : "default"    }}

Now save your file anywhere in your system with the extension apns. I am saving my payload file named “demo.apns”. Please note that extension of the file you save must be apns.

Note that the value of “Simulator Target Bundle” will be the bundle ID you just retrieved from Xcode. Please replace the bundle id with the bundle id you just retrieved from your project.

Finally we are ready to test our payload. The wait is over.

Testing our payload just requires dragging our payload to the simulator. As soon as you drag and leave your payload file to simulator a notification banner according to your payload pops out.

Dragging apns file to simulator

Congratulations, you have just received your first push notification in the simulator using your own payload file. 🎉

If you do not see a push notification banner popping up after dragging the payload file on the simulator, please check whether your project target with bundle id used in the payload file is installed in the simulator or not. Or you could just simply run your target again on the simulator and then again try dragging the payload file. The app with the bundle id used in the payload must be installed in the simulator to pop out the push notifications.

If you want to know more about the possibilities with payload it is always a good idea to go through an official documentation.

--

--