iOS未从Firebase Cloud Messaging接收通知 [英] iOS not receiving notifications from Firebase Cloud Messaging

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

问题描述

我希望推送通知仅包含标题.当我从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 Cloud Messaging接收通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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