iOS 未收到来自 Firebase 云消息传递的通知 [英] iOS not receiving notifications from Firebase Cloud Messaging

查看:34
本文介绍了iOS 未收到来自 Firebase 云消息传递的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望推送通知只包含标题.当我从 Firebase 控制台发送消息时,它可以工作,但是当我尝试通过 API 执行相同操作时,它不适用于 iOS(在 Android 上工作正常).

I want the push notification to only contain the title. When I send a message from the Firebase console, it works, but when I try to do the same via the API, it doesn't work for iOS (works fine on Android).

我想要完成的是仅在应用程序未打开时显示在通知抽屉中的通知中显示标题.如果添加了正文,它会显示在通知的标题下.

What I'm trying to accomplish is to only show the title in the notification that shows up in the notification drawer when the app is not open. If body is added, it is shown under the title in the notification.

这是我发送的推送通知:

This is the push notification I'm sending:

{
    "to": "/topics/breaking",
    "priority":"high",
    "notification": {
        "title":"Dette er en test"
    }
}

我一无所获

如果我向通知添加正文:

If I add body to the notification:

{
    "to": "/topics/breaking",
    "priority":"high",
    "notification": {
        "title":"Dette er en test",
        "body":"hello"
    }
}

我得到这个作为回报

{
    aps = {
        alert = {
            body = Hello;
            title = "Dette er en test";
        };
    };
    "gcm.message_id" = "xxxxxxx";
}

这是打印我收到的内容的代码:

Here is the code to print out what I receive:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    self.parseNotification(application, userInfo: userInfo as NSDictionary!)
}

func parseNotification(_ application: UIApplication, userInfo: NSDictionary!) {

    print(userInfo)
}

如何在不向请求中添加正文的情况下在 iOS 上获取通知?

How can I get the notification on iOS without adding body to the request?

推荐答案

我想通了!

如果我放弃标题并只发布正文,它就可以工作.

If I drop the title and ONLY post body it works.

{
    "to": "/topics/breaking",
    "priority":"high",
    "notification": {
        "body": "Dette er en test"
    }
}

这篇关于iOS 未收到来自 Firebase 云消息传递的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆