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