Test FCM notification on iOS Simulator

Viewed 9148

Since Xcode 11, iOS simulators can now receive push notifications. This can be accomplished by executing a specific command or providing a JSON file to the simulator. I got this information from this blog: Test Notification on Simulator.

However, in my use case, I use Firebase Cloud Messaging to deliver notifications to the user of my app (Android and iOS both). I am unable to test the notification generated by Firebase on a simulator as the payload is different for FCM.

Is there a way to achieve this?
I found a similar question on the topic but there's no answer on it so far.

2 Answers

For Testing push notifiction in simulator just creat a new file and paste following json object and save file in .apns , and then just drag and drop this file in simulator then push will work.

{
    "aps" : {
        "alert" : {
            "title" : "sarunw.com",
            "body" : "A asdfsadfsadf"
        },
        "badge" : 5
    },
    "Simulator Target Bundle": "bundleId"
}

For differenct payload just use following JSON object in Postman

{
 "to" : "ewebWDSSwYc:APA91bGOARO4eq9LlOfgfXPQZMK3IiRFanhzSSgkD6cVqJiPbnyuEgsvQMarDEl6Hg7_UMtFM6Hn90jyTsSENNqLNNLVjLSypR0voAO3j6orIsgabX-t0cpfJ0qpB2SzhZiXvor0r__d",
 "notification":
 {
    "title":"ABC",
    "body":"123",
    "mutable_content" : true,
    "category":"CustomSamplePush"
 },
 
 "data":
    {
        "sender_contact_code" : "+92",
     "sender_contact" : "(555) 564-8583",
     "group_name":"Testing Group",
     "type":"NewMessage",
     "type_id":"1213",
     "notification_type_id":"123213"
    }
}

with this url -> https://fcm.googleapis.com/fcm/send (Type will be POST)and in authorization you need to put Server key in Key Value, in that way you will be able to send push notification with your own formatted object.

also you can use Pusher for testing push notifiction & I have uploaded screenshot for reference.

postman_screenshot

Since Xcode 12 (not 11), it's possible to registrer to push and receive via the APNS payload. If the drag & drop it not working, you can use Terminal :

xcrun simctl push booted YOUR_BUNDLE payload.json

With :

  • "booted" = the current simulator
  • "payload.json" = the APNS file on your Mac.

It may look like:

{
    "Simulator Target Bundle": "xxx.xxx.xx ",
    "aps":{
                    "alert":{
                        "title":"XXX",
                        "body":"YYY YYYY"
                    },
                    "badge" : 5,
                    "data":{
                        // stuff
                    },
                    "mutable-content":1
                }
}
 
Related