1
votes

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).

Edit: 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"
    }
}

And I get nothing back

If I add body to the notification:

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

I get this in return

{
    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)
}

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

2
Why don't you just ignore body while parsing userInfo? - Vishal Sonawane
The problem is the notification that shows up in the notification drawer when the app is not open. It should only contain the title. - fknChaos
Ah. So you mean the top banner only shows when the app is not opened? - Zonily Jame
This is what the behaviour of iOS is like if that's what you mean. You'd have to use a custom view to mimic the banner behaviour when your app is in Foreground/Active state. For iOS 9 you could use UNUserNotifications - Zonily Jame
@ZonilyJame Tried it. Looked a bit weird. - fknChaos

2 Answers

3
votes

I figured it out!

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

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

Please try to add certificates for push notifications: for development and production.