【问题标题】:iOS Firebase Push notification not working on simulator with Xcode 11.5 and iOS 13iOS Firebase 推送通知在 Xcode 11.5 和 iOS 13 的模拟器上不起作用
【发布时间】:2020-10-12 06:27:17
【问题描述】:

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

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

【问题讨论】:

  • 能否提供更详细的信息?
  • 我尝试在模拟器(Xcode 11.5 和 iOS 13)上获取推送通知,我尝试了所有方法,但仍然缺少一些东西。消息(有效负载)显示在控制台上(使用 remoteMessage.appdata),但没有显示在模拟器上。 UNUserNotificationCenter 不工作。从 firebase 控制台发送通知时,只调用了 didReceiveMessage 方法,而不调用其他方法。谢谢

标签: ios objective-c firebase firebase-cloud-messaging apple-push-notifications


【解决方案1】:

您可以关注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

【讨论】:

  • 感谢您的回复,我尝试了上述解决方案,但收到如下错误,处理命令时遇到错误 (domain=NSCocoaErrorDomain, code=3840): The data could not be read because it格式不正确。数据格式不正确。
  • 此消息表示系统无法解析 json。复制我也在答案中发布的正确 json。
  • 这里可能是 .apns 文件格式,{ "Simulator Target Bundle": "my projects bundle identifier", "aps": { "alert": { "title": "Push on the simulator" , "subtitle": "测试推送通知", "body": "这个通知会出现在模拟器中!" } } }
猜你喜欢
  • 2020-01-31
  • 2019-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-02
  • 2012-02-17
相关资源
最近更新 更多