Testing Remote Push Notifications with iOS Simulators
This week, in my newsletter series "Building a Newsletter App" series, I walked through how to set up push notifications. I initially planned to include tips on testing with iOS simulators, but since it's a tricky topic - due to limited access to production servers and the simulator's lack of native support for remote notifications - I decided to put together a simple, focused guide just for that!
Working with Push Notifications
When dealing with push notifications, it's important to understand what a payload is. A payload is the actual content of the notification - the data you want to send to users. This data is structured as a JSON dictionary and includes various fields to declare the notification.
Creating the Remote Notification Payload
To simulate a push notification on the iOS simulator, the first thing we will need is a properly formatted Apple JSON payload.
Here is how we can create one:
{
"aps" : {
"alert" : {
"title" : "New Issue is live 🚀🚀🚀",
"body" : "Check issue #44 and learn how to set up push notifications."
},
"sound" : "default"
},
"link": "ioscoffeebreakapp://issue?id=44"
}
For more information, check Apple's official documentation on how to generate a remote notification.
The Plan
I decided to try out three different methods for testing remote push notifications in the iOS simulator — each with its own advantages:
- Testing with an APN certificate
- Testing from the Command Line
- Testing with RocketSim
Testing with an APN certificate
To build the JSON payload our app expects when receiving a push notification, follow these steps:
- In Xcode, go to File > New > File > File from Template, and type JSON.
- From the dialog window, select GeoJSON File.
- Give the file a name like AlertPushNotification and proceed to create it.
- Xcode will add the .geojson extension by default. Rename the file and change the extension to .apns, resulting in AlertPushNotification.apns.
- Then, replace the contents of the file with your push payload — you can use the sample snippet below to start.
{
"Simulator Target Bundle": "<app-bundle-identifier>",
"aps" : {
"alert" : {
"title" : "New Issue is live 🚀🚀🚀",
"body" : "Check issue #44 and learn how to set up push notifications."
},
"sound" : "default"
}
}
Replace "app-bundle-identifier" with your app's bundle identifier (e.g., com.tiago.henriques.iOSCoffeeBreak).
Now, launch the app and press "cmd + l" to lock the simulator — this brings up the home screen. Then, simply drag your AlertPushNotification.apns file to the simulator.
That's it! 🎉 You should see the notification appear along with the default alert sound.
Testing from the Command Line
simctl
is a command-line utility that lets you interact with the iOS simulator.
If you have Xcode installed and you should, then you can access it using the xcrun
command.
To simulate a push notification using the terminal, follow these steps:
- Launch your app on the simulator.
- Open your terminal window.
- Navigate to the folder where your AlertPushNotification.apns file is located.
- Then, run the following command:
$ xcrun simctl push booted <app-bundle-identifier> <apns-file>
Replace "app-bundle-identifier" with your app's bundle identifier (e.g., com.tiago.henriques.iOSCoffeeBreak) and "apns-file" with the APN file you have just created (e.g., AlertPushNotification.apns).
Testing with RocketSim 🚀
There are many tools available for testing push notifications, but I picked RocketSim to showcase how simple the process can be.
Here is how to simulate a notification using RocketSim:
- Launch RocketSim and go to Settings > App Actions.
- Create a new group (e.g., iOS Coffee Break).
- Enter your app's bundle identifier in the provided field.
- Switch to the Push Notifications tab and click the "+" button.
- Give your push a name and paste in the JSON from your .apns file.
- Hit Create.
Now, with RocketSim running, access the floating menu. Under the App Actions tab (third icon), we will find your custom push notification — click it to see the simulated notification pop up in the simulator!
🤝 Wrapping Up
In this post, we explored three different methods for testing and simulating remote push notifications using the iOS simulator. Try them out, experiment with what works best for your workflow, and choose the approach that fits your preferences or project setup.