Kasra
Kasra

Reputation: 2189

Test react native firebase push notification in simulator

According to the react native firebase doc, the push notification does not work in simulator. Even Out-of-app notifications (when app is in background and you see the notification in the status bar) does not work when you run the app on your real ios/Android device connected to your PC by cable. (In-app notifications work though using messaging().onMessage)

Current behavior: My Firebase push notification works perfectly on both Android and ios in standalone apk/ipa. However, I cannot test it during development on simulator.

Desired behavior: I want to receive push notification (Out-of-app notification) when the app is running on simulator in background, so that I can use messaging().onNotificationOpenedApp method as usual.

Why I need this? Of course, each time I make a change regarding push notification, I can create a standalone app, install it on phone to see how it works. This approach has many issues:

  1. It's super time-consuming and does not make sense at all
  2. If the code does not work as expected, there is no way to check what goes wrong
  3. There is no console.log, in general, no way to debug the code

Upvotes: 8

Views: 6406

Answers (2)

basvk
basvk

Reputation: 4546

For firebase's messaging().onNotificationOpenedApp to be triggered I used the following payload json:

{
  "Simulator Target Bundle": "bundle.identifier",
  "google.c.a.e": 1,
  "foo": "bar",
  "aps": {
      "alert": "Alert!",
      "content-available": 1
  },
  "gcm.message_id": "0:1538488916770554%a88db343a88db34"
}

Upvotes: 4

Mohsen
Mohsen

Reputation: 1555

Finally, you can do this in Xcode 11.4 and later (Release note).

Simulator supports simulating remote push notifications, including background content fetch notifications.

Also here you can find a step-by-step guide to do that, based on react native.

Upvotes: 2

Related Questions