How to test Push Notifications in the simulator


You’re more of a video kind of person? I’ve got you covered! Here’s a video with the same content than this article 🍿


If you’ve ever had to implement Push Notifications inside an iOS app, you know that getting them to work is never as easy as it seems!

Between the certificates that need to be installed on your back-end and the configuration to send the notifications to the right environment, it can easily become a very time activity consuming…

And because of that, testing a push notification becomes an extremely painful task, that you end up doing as little as possible.

But did you know that Xcode actually has a feature that makes it extremely easy to locally test a push notification in the simulator?

All you need for that is to create a new text file with a .apns extension:

And then populate this new file with the following JSON data:

As you can see, this file contains the typical payload of a push notification, along with the bundle identifier of the app that will receive the notification.

And now there’s only step left: delivering the notification to the iOS app.

There are actually two ways this can achieved.

The easiest one is to simply drag-and-drop the notification file over the simulator:

But you can also deliver the notification through the terminal, by running the following command line:

$ xcrun simctl push booted test-notification.apns

As you can see, both approaches are significantly simpler and faster than sending a real test push notification!

So if your app relies on push notifications, I would really recommend that you take the time to create some .apns files, so that you can regularly test that all your notifications are working correctly 😌

By the way, if you’re looking for a tool that can help you make the most of the iOS simulator, I can recommend that you check out RocketSim from Antoine van der Lee: it supports triggering push notifications, along with many other cools features 🚀

Previous
Previous

What’s the difference between any and Any?

Next
Next

Swift has more formatters than you know!