ios - 在 iPhone 上接收推送通知

标签 ios iphone cordova firebase push-notification

你好,我被困住了,我需要帮助。 我有一个使用 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 证书(通过 key )设置 APNS-FCM 连接。两次尝试都没有给我积极的结果......

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

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

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

请帮帮我

最佳答案

确保您在有效负载中发送了 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 编码向所有推送服务发送负载字段。

关于ios - 在 iPhone 上接收推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50372189/

相关文章:

javascript - 无法访问根目录 phonegap

iphone - 移动棒图、 anchor 、动画或其他东西......?

ios - NSBundle pathForResource 不适用于子目录本地化?

ios - Firebase iOS 推送通知在首次应用启动时未收到

ios - 在 stackview 中隐藏按钮会破坏 tableview 中的布局

iphone - 如何收集信用卡信息

ios - 分析 CAKeyframeAnimation 时出现警告

javascript - HTML5 本地存储 : Checking if a key exists

ios - Cordova /PhoneGap : childBrowser UI images low res/chunky (iOS)

ios - 当用户使用调试工具跟踪代码时,如何使IOS Framework进行封装?