Xcode 11.4 beta 1 surprised us last week with a long awaited feature: push notifications on the simulator! (standing ovation).

As anyone that ever had to debug push notifications on iOS knows, the process (depending on your backend implementation) is a bit of a hassle. Starting from the fact that a custom back end implementation might not have an easy way of sending push notifications in development/testing/staging environment, to the fact that you need an actual device to receive those notifications on. And as anyone who ever had to work with manual provisioning knows, that might come with it’s own set of headaches.

But problems no more! Both actual issues have been corrected with the latest beta release. You don’t actually need to send them from your backend and you don’t need a physical device anymore.

At this point you’re thinking “Yay! There’s probably a hidden submenu somewhere in the simulator toolbar”, but think again. If we’re used to Simulate Location or Simulate Memory Warning , this is not so straightforward.

For this, we actually need to use xcrun. If that’s something that’s new to you, let’s take a look at the man description:

xcrun provides a means to locate or invoke coexistence- and platform-

aware developer tools from the command-line, without requiring users to

modify makefiles or otherwise take inconvenient measures to support mul-

tiple Xcode tool chains.



The tool xcode-select is used to specify which installation of Xcode is

used, and may be overridden by the DEVELOPER_DIR environment variable.



The SDK defaults to the boot system OS SDK, and can be specified by the

SDKROOT environment variable or the -sdk option (which takes precedences

over SDKROOT).

TL;DR xcrun is a command line tool which allows you to find or run any tool inside Xcode from the command line.

Let’s now take a look on how we can do this, but before you get started, make sure you have Xcode 11.4 beta 1 installed (it would be a good place to mention that Xcode 11.4 will require macOS Catalina — RIP Mojave).

There are 3 ways of doing this, and two of them need us to create a notification file, an apns file, which contains the body of the notification. Apple has a good in-depth tutorial on how to build one, which you should read, but until then, I’m gonna paste the body of one here:

Save it somewhere easy to access, like your desktop, with the apns extension.

First way:

We need to find the current running simulator. For this, open your terminal of choice and run

xcrun simctl list | grep (Booted)

This will output a list of booted simulators. In my case I have

After the simulator name we have the identifier, the long UUID in parenthesis. We need that.

2. Now that we have the apns and the simulator UUID, we just need to run the command

xcrun simctl push <UUID> <AppBundleId> <PathToNotification>

and we should get a successful output

Second way:

Remember the notification we saved on our desktop? Let’s edit it and add the following line containing the app’s bundle identifier

“Simulator Target Bundle”: “<AppBundleId>”

so our file content now is

2. Save the changes

3. Drag and drop the file anywhere on the simulator window.

MAGIC!!!

Third way (shameless plug):

I’ve created a simple app available for free here. It’s opensource and you also have a precompiled executable available if you’re not interested in the all the under-the-hood goodies. Just download it, fill in the necesary info and remember to have fun!

Apple blessed us with this feature so we should enjoy it.

Happy coding!