public void CreateNotification(NotificationAlertMessage message, bool IsLocal, Dictionary <string, string> Parameters) { if (message != null) { if (IsLocal == false) { //await IncrementNotificationCount(); } // TODO: set values to be passed to notification when user clicks on it var dic = new NSMutableDictionary(); dic.Add(new NSString(notificationlocal), new NSString(IsLocal ? "1" : "0")); if (Parameters == null) { dic.Add(new NSString(notificationAlertKey), new NSString("1")); } else { foreach (var item in Parameters) { dic.Add(new NSString(item.Key), new NSString(item.Value)); } } // TODO: get the body of the notification from a service if available GlobalSettings.InvokeOnMainThread(() => { var state = UIApplication.SharedApplication.ApplicationState; //System.Diagnostics.Debug.WriteLine("app state:= " + state); var notification = new UILocalNotification(); notification.FireDate = Foundation.NSDate.Now.AddSeconds(1); // configure the alert stuff notification.AlertAction = message.Title; notification.AlertBody = message.Message; //notification.ApplicationIconBadgeNumber = getBadgeCountNoLock(); notification.UserInfo = dic; notification.AlertTitle = message.Title; // set the sound to be the default sound notification.SoundName = UILocalNotification.DefaultSoundName; // schedule it UIApplication.SharedApplication.ScheduleLocalNotification(notification); }); } }
// TODO: this method will change based on your app rules to handle notifications // see Notification Objects format in notificationFormats.txt // If you use a different platform, you have a different values public object getMessage(Dictionary <string, string> values, bool AppActive) { string body = string.Empty; string title = string.Empty; Int32 messageID = 0; NotificationAlertMessage msg = null; foreach (var item in values) { if (item.Key == "alert") { /* Format Expected * { * body = "Andrew test message. testing psea notifications."; * title = test; * } */ // TODO: change based on your format var obj = AlertKeyParse(item.Value); body = obj["body"]; title = obj["title"]; } else if (item.Key == "messageID") { messageID = Convert.ToInt32(item.Value.ToString()); } } if (body != null) { // TODO: create object msg = new NotificationAlertMessage(); msg.Message = body; msg.MessageID = messageID; msg.Title = title; return(msg); } return(null); }