iOS Firebase 推送通知无法在 Xcode 11.5 和 iOS 13 的模拟器上运行

iOS Firebase Push notification not working on simulator with Xcode 11.5 and iOS 13

我已尝试使用 Firebase 推送通知,但它不起作用。远程消息显示在带有负载的控制台上,但未在模拟器上显示通知。我使用 Xcode 11.5 和 iOS 13.

  1. 已将 GoogleService-Info.plist 添加到根文件夹
  2. 是否完成了 Firebase 推送通知所需的所有代码
  3. 已在 firebase 控制台上传 .p12 文件
  4. 在 Xcode
  5. 上添加了推送通知功能

您可以按照 this article 在模拟器中测试推送通知。要测试直接从 firebase 发送的远程通知,您需要一个物理设备。我正在使用 xcode 11.6,在注册过程中它在控制台中显示一条消息:Error! iOS Simulator does not support push! Please test on a real iOS device. remote notifications are not supported in the simulator

以下是在模拟器中测试推送通知的摘要:

  • 注册推送通知并确保您允许它。
  • 创建一个名为:test_push_notification.apns
  • 的文件
  • 只需根据您的应用替换包标识符,即可在新创建的文件中添加并保存以下内容 JSON。
  • { "Simulator Target Bundle": "com.yourapp.bundleid", "aps": { "alert": { "title": "在模拟器上推送", "subtitle": "测试推送通知" , "body": "此通知将显示在模拟器中!" } } }
  • 打开终端并导航到您保存文件的目录。
  • 运行 这个命令 xcrun simctl push booted test_push_notification.apns