question

Kim Strasser avatar image
Kim Strasser asked

iOS push notifications: Title not included in payload

I use a cloud script to send push notifications to iOS and Android devices. In my Android application, I get both title("Welcome message") and body("Hello") of the push notification in the payload. But on iOS, I only get the body in the payload.

Right now, all my push notifications have the same title("Title of this message!") on iOS because I don't get the title here in the payload:

In this picture, you can see that there is only alert = Hello and badge = 0, but the title is missing in the payload(userInfo).

My cloud script:

handlers.Welcome = function (args, context)
{
        var targetId = args.TargetId;
        server.SendPushNotification({ Recipient : targetId, Package : { GeneratePlayStreamEvent : true, Message : "Hello", Title: "Welcome message" }});
        log.info("This is a log statement!");
        log.debug("This is a debug statement.");
        log.error("This is... an error statement?");
}

Why is the push notification title not included in the payload on iOS? Is this a bug or am I doing something wrong?

My iOS application code to receive push notifications:

        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            ProcessNotification(userInfo, false);
        }

        void ProcessNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            // Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;

                if (aps.ContainsKey(new NSString("alert")))
                    alert = (aps[new NSString("alert")] as NSString).ToString();

                if (!fromFinishedLaunching)
                {
                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        NSString alertKey = new NSString("alert");
                        UILocalNotification notification = new UILocalNotification();
                        notification.FireDate = NSDate.Now;
                        notification.AlertTitle = "Title of this message!";
                        notification.AlertBody = aps.ObjectForKey(alertKey) as NSString;
                        notification.TimeZone = NSTimeZone.DefaultTimeZone;
                        notification.SoundName = UILocalNotification.DefaultSoundName;
                        UIApplication.SharedApplication.ScheduleLocalNotification(notification);
                    }
                }
            }
        }
Push Notifications
payloadios.jpg (228.0 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

Have you tried SendPushNotificationFromTemplate API to send notification? I will inform our team about the missing title in the push notification payload.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kim Strasser avatar image Kim Strasser commented ·

Thank you. It works with the SendPushNotificationFromTemplate API. I get the title and the body of the push notification with this code:

string Title = "";
string Body = "";

if (aps.ContainsKey(new NSString("alert")))
{
  Title = ((options["aps"] as NSDictionary)["alert"] as NSDictionary)["title"] as NSString;
  Body = ((options["aps"] as NSDictionary)["alert"] as NSDictionary)["body"] as NSString;
}
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

My suggestion is trying to use push notification template if it fulfills your requirements because it is a comparatively new feature. The legacy push notification system is using Amazon SNS and even though we will still keep supporting it but not sure how long.

Feel free to tell us if you have any issues when using push notification template.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.