Xcode 11.4 introduced sending simulated push notification on iOS simulator
How to achieve that?
Answering my own question :P
Requirement: Xcode 11.4 beta or above
Use online tool to test push notifications, I personally found it more useful than methods below, it's more straightforward and does not require remembering simctl
command
Website: http://pushplayground.com/
There are 2 ways, both needed a JSON formatted 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
.apns
file to simulatorWhen 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Ă !