Prerak Sola
Prerak Sola

Reputation: 10019

Test FCM notification on iOS Simulator

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.

Upvotes: 11

Views: 14772

Answers (3)

Adrien Binder
Adrien Binder

Reputation: 1

maybe you found the solution a long time ago but here is how i made it work: to allow FCM notification to be catch in your app you need to add that in your .apns file

"gcm.message_id":"20021"

here is the apns file i use to test FCM notifs on my Iphone simulator:

{
    "Simulator Target Bundle": "XXX.XXXXXX.XXX",
    "aps": {
      "alert" : {
         "title" : "Test notif",
         "body" : "Should update widget && refresh feed"
      },
   },
   "gcm.message_id":"20021",
   "data": {}
}

Upvotes: 0

Chandaboy
Chandaboy

Reputation: 1359

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

Upvotes: 10

Medhi
Medhi

Reputation: 3245

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
                }
}
 

Upvotes: 0

Related Questions