简体   繁体   English

在模拟器中测试本机 firebase 推送通知

[英]Test react native firebase push notification in simulator

According to the react native firebase doc, the push notification does not work in simulator.根据 react native firebase doc,推送通知在模拟器中不起作用。 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.当您在通过电缆连接到 PC 的真实 ios/Android 设备上运行应用程序时,即使应用程序外通知(当应用程序在后台并且您在状态栏中看到通知时)也不起作用。 (In-app notifications work though using messaging().onMessage ) (应用内通知通过使用messaging().onMessage起作用)

Current behavior : My Firebase push notification works perfectly on both Android and ios in standalone apk/ipa.当前行为:我的 Firebase 推送通知在独立 apk/ipa 中的 Android 和 ios 上都能完美运行。 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.期望的行为:我想在应用程序在后台模拟器上运行时接收推送通知(应用程序外通知),以便我可以像往常一样使用messaging().onNotificationOpenedApp方法。

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没有console.log ,一般情况下是没办法调试代码的

Finally, you can do this in Xcode 11.4 and later ( Release note ).最后,您可以在 Xcode 11.4 及更高版本( 发行说明)中执行此操作。

Simulator supports simulating remote push notifications, including background content fetch notifications. Simulator 支持模拟远程推送通知,包括后台内容获取通知。

Also here you can find a step-by-step guide to do that, based on react native.同样在这里,您可以找到基于 react native 的分步指南。

For firebase's messaging().onNotificationOpenedApp to be triggered I used the following payload json:为了触发firebase的messaging().onNotificationOpenedApp ,我使用了以下有效负载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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM