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.
xcrun 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
# Sends a push notification to 'iPhone 13' Simulator. id=$(uuidgen | awk '{print tolower($0)}') echo '{ "Simulator Target Bundle": "com.example", "aps": { "mutable-content": 1, "alert": "Test", "relevance-score": 0, "interruption-level": "active", "sound": "default" }, "custom": { "i": "'$id'", "u": "example://example.com/link/to/item", "a": {} } }' > $id.apns echo "Sending push with ID=$id" xcrun simctl push 'iPhone 13' com.example $id.apns rm $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.
$ chmod +x send-push.sh
$ ./send-push.sh