【问题标题】:Receiving Push Notification on the Iphone在 Iphone 上接收推送通知
【发布时间】:2018-10-26 14:02:52
【问题描述】:

您好,我被困住了,我需要帮助。 我有一个使用 Angular2 + Cordova + cordova-firebase-plugin + xcode 构建的 iOS 应用程序。

我已经在 developers.apple.com 和 firebase.console 网站上设置了该应用程序。 现在,当我尝试发送通知消息时,我在 Iphone 上根本收不到它。

如果应用程序在前台运行,我会在调试控制台中看到收到通知,但它没有显示在 Iphone 上。

来自控制台的消息:

Received data message: {
    "collapse_key" = "com.example.app"
    from = 793840040300;
    notification = {
        body = "example test notification message";
        e = 1;
    }
}

我在这里看不到:通知标题。 (通知在 Android 中有效,但在 iOS 中无效)。 没有任何关于启用通知的提示(权限提示)。

我尝试通过 .p12 证书和 .p8 证书(通过密钥)设置 APNS-FCM 连接。这两个尝试都没有给我积极的结果......

还有一点: 如果应用程序在后台运行 - 在我打开应用程序之前,我不会在控制台中看到消息。当我打开应用程序时,如果消息是在应用程序处于前台时发送的,则会出现在控制台中..

我查看了许多不同的指南,但没有得到任何结果。

我读到模拟器不支持推送通知,所以我通过 USB 连接了一个真实设备。而且它的行为相同 - 没有收到推送通知 - 只有控制台中的消息。

请帮帮我。

【问题讨论】:

  • 触发通知时您的应用程序是否在前台?
  • 没关系。我都试过了。在前台和后台
  • 在设备设置->通知->你的应用。是否启用通知?
  • 在设置->通知中设置为“始终”显示

标签: ios iphone cordova firebase push-notification


【解决方案1】:

确保在负载中同时发送titlebody。我有一个问题(在 Android 中),当不发送 message 项目时,通知不会显示在通知栏中。这同样适用于 iOS,但在这种情况下,变量是 titlebody

如果在有效负载中找不到正确的变量,Android、iOS 和 Windows Phone 都会将其视为后台通知,以静默方式传送到应用程序(一旦打开)。通知不会唤醒已卸载的应用,在这种情况下,一旦从通知栏中选择通知项,该应用就会由通知项启动。

尝试从documentation 发送默认有效负载进行测试:

{
  "aps": {
    "alert": { // alternatively just a string: "Your Message",
      "title": "A short string describing the purpose of the notification",
      "body": "The text of the alert message",
      // localization of message is possible
      "launch-image": "The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider"
    },
    "badge": 5, // Number to show at App icon
    "content-available": "0", // configure background updates, see below
    "category": "identifier", // Provide this key with a string value that represents the notification’s type
    "thread-id": "id", // Provide this key with a string value that represents the app-specific identifier for grouping notifications
    "sound": "default"  // play default sound, or custom sound, see [iOS Sound](#sound-1) section
  },
  "custom_key1": "value1",
  "custom_key2": "value2"
}

如果这不起作用,请包含您从服务器端发送到 APNS 的有效负载的全部内容。

编辑:确保您以 UTF-8 编码将负载字段发送到所有推送服务。

【讨论】:

  • 我正在使用 Firebase 控制台网站 Push Notifications Message Composer 来测试通知。我认为默认情况下应该创建正确的通知,因为它同时支持:android 和 iOS。我不直接使用 APN,我使用的是 google 提供的 Firebase Cloud Messaging。
猜你喜欢
  • 2015-11-26
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
  • 2013-01-14
相关资源
最近更新 更多