Displaying FCM notifications on iOS Simulators

Alimov Shohrukh
3 min readApr 1, 2022

FCM via APNs does not work on iOS Simulators. To receive messages & notifications a real device is required… okay, jeez, give us a break Apple, willya?

I don’t own an iPhone and it’s been always pain in the ass for me to test push notifications borrowing someones device 😑. Recently, working on my next contract as mobile developer at Kazakhstan’s one of the biggest trade and retail platforms Magnum, I had to add a feature in our (Flutter) app which required to show pop-up (on foreground) and system tray notification (in background) and navigate users on tap through the app accordingly. For cloud messaging we’ve used Firebase (obviously). To construct the payloads and local tests I’ve used Gorush (kudos to appleboy). Voilà, we have our Android ready.

Now, for iOS part I knew that I needed real device. But, thanks to the updates by Apple team, starting from Xcode 11.4, it is now possible to simulate push notifications by dragging and dropping an .apns file onto the iOS simulator

Simulator supports simulating remote push notifications, including background content fetch notifications. In Simulator, drag and drop an APNs file onto the target simulator. The file must be a JSON file with a valid Apple Push Notification Service payload, including the “aps” key. It must also contain a top-level “Simulator Target Bundle” with a string value matching the target application‘s bundle identifier.

And here is how we can do it

Create fcm_example.apns file targeted towards your app like below

{
"Simulator Target Bundle": "your.app.identifier",
"aps": {
"alert": "Push-уведомление для симулятора!",
"badge": 1,
"sound": "default"
}
}

Dragging and dropping this onto the target simulator will present the notification with badge

Same result with simctl

simctl also supports sending simulated push notifications. If the file contains “Simulator Target Bundle” the bundle identifier is not required, otherwise you must provide it as an argument (8164566):

xcrun simctl push <device> your.app.identifier fcm_example.apns

Note: Notification Service Extensions do not work in simulated push notifications. The mutable-content key is not honored. (55822721)

For Firebase messaging, it requires gcm.message_id value to be present. Otherwise it won't be handled by firebase SDK

"gcm.message_id": "0123",

Key-values

For me, adding key-values didn’t quite work but, you can still try you luck. Just add you key-value as below

"some-key": "some-value",
"some-key": "some-value",

Heres how my full fcm_example.apns file looked like

{
"Simulator Target Bundle":"----",
"aps":{
"alert":"Push-уведомление для симулятора!",
"badge":1,
"sound":"default"
},
"type":"Какой-то тип",
"id":Какой-то ID,
"gcm.message_id":"20021"
}

That’s it. Later on, I’m planing to make a post about configuring Gorush for local Firebase Cloud Messaging push notification tests using Flutter for both iOS and Android devices. Cheers!

References:

--

--

Alimov Shohrukh

Working w/ amazing people to benefit people's life 🖖🇺🇿 Great guy according to my boss ♦️ CTO @ OQ ♦️ Head of Development @ Beeline Uzbekistan