Testing remote push notifications on iOS simulator in Xcode 14
I recently discovered that starting from Xcode 14 we can test remote push notifications on an iOS simulator. Before this, simulators were unable to provide a device token, limiting us to locally simulating notifications using .apns
payload files and the simctl push
command.
To be able to send remote push notifications to an iOS simulator in Xcode 14, we have to be running macOS 13 on a computer with an Apple silicon or a T2 processor. In this setup, the simulator generates a unique registration token, which is specific to the combination of the simulator and the Mac hardware it’s running on.
The simulator supports the Apple Push Notification Service (APNS) Sandbox environment, which means that we have to connect to api.sandbox.push.apple.com
to send a notification to the simulator.
I think this feature is great, since it lets us test the entire process of sending a push notification, when we don't have a real device at hand. It also allows us to use the simulator for testing more features, like Notification Service Extensions, that wasn't possible with .apns
payload files or the simctl push
command in the terminal.
If you're an experienced Swift developer looking to learn advanced techniques, check out my latest book Swift Gems. It’s packed with tips and tricks focused solely on the Swift language and Swift Standard Library. From optimizing collections and handling strings to mastering asynchronous programming and debugging, "Swift Gems" provides practical advice that will elevate your Swift development skills to the next level. Grab your copy and let's explore these advanced techniques together.
I’m currently running a Black Friday 2024 promotion with 30% off my books, plus additional savings when purchased as a bundle. Visit the books page to learn more.