Xcode 11.4 introduced sending simulated push notification on iOS simulator
How to achieve that?
“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.
Conclusion. Thanks to this new functionality that we can see in the beta version of Xcode 11.4, we can already test the push notifications, and the behavior of our applications when receiving them, from the simulator itself, without the need of a physical device.
Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.
How to simulate location in Simulator. To simulate location on a Simulator, select Features menu > Location, then you will see a list of location and movement options you can simulate.
Answering my own question :P
Requirement: Xcode 11.4 beta or above
There are 2 ways, both needed a JSON file with a valid Apple Push Notification Service payload (with .apns extension)
Example apns: (Save it as XXX.apns file)
{
"aps":{
"alert":"Test",
"sound":"default",
"badge":1
}
}
Using simctl
to send simulated notification
$ xcrun simctl push <SIMULATOR_DEVICE_ID> <YOUR_APP_BUNDLE_ID> <APNS_FILE_NAME>
Usage:
$ xcrun simctl push A0AF405F-FE73-45DA-8D7D-F1FE37821992 com.example.my-app test.apns
You can find the simulator device id with
xcrun simctl list
Example:
When using drag and drop, you apns file needed to include a key that indicates your app bundle id
Key name: Simulator Target Bundle
Value: Your app bundle id
Example:
{
"Simulator Target Bundle": "YOUR_APP_BUNDLE_ID",
"aps":{
"alert":"Test",
"sound":"default",
"badge":1
}
}
After that, simply drag and drop the file into the simulator, and voilà!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With