Vojtech Pavlovsky

OneSignal Notifications on iOS Simulator

Apple now allows to send mock notifications to the iOS Simulator.

Unlike the Android Emulator where you test notifications from your OneSignal Dashboard, on iOS you can only simulate them locally. To send a push notification to Simulator, you have to first create file with .apns extension. This file can be sent by following command.

1xcrun simctl push <device> <bundleId> mock-notification.apns

However, OneSignal uses custom format for notification payload like deeplink. To be more complicated, each notification requires a unique ID. Multiple notifications with same ID will not work properly.

You can use following shell script to generate notification's UUID, inject it into notification payload and trigger send to your Simulator.

send-push.sh
1# Sends a push notification to 'iPhone 13' Simulator.
2
3id=$(uuidgen | awk '{print tolower($0)}')
4echo '{
5 "Simulator Target Bundle": "com.example",
6 "aps": {
7 "mutable-content": 1,
8 "alert": "Test",
9 "relevance-score": 0,
10 "interruption-level": "active",
11 "sound": "default"
12 },
13 "custom": {
14 "i": "'$id'",
15 "u": "example://example.com/link/to/item",
16 "a": {}
17 }
18}' > $id.apns
19echo "Sending push with ID=$id"
20xcrun simctl push 'iPhone 13' com.example $id.apns
21rm $id.apns

Copy this content into file named send-push.sh. You will need to customize bundle (com.example) and Simulator name (iPhone 13).

Shell script can be run using following commands.

1$ chmod +x send-push.sh
2$ ./send-push.sh