public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { // Take action based on Action ID switch (response.ActionIdentifier) { case "reply": // Do something break; default: string identifier = response.ActionIdentifier; // Take action based on identifier if (response.IsDefaultAction) { var storyboard = UIStoryboard.FromName("Main", null); NotificacionViewController notificacion = storyboard.InstantiateViewController("NotificacionView") as NotificacionViewController; if (notificacion != null) { NotificacionViewController.titulo = response.Description; NotificacionViewController.descripcion = Description; notificacion.ShowViewController(notificacion, this); } } else if (response.IsDismissAction) { // Handle dismiss action } break; } // Inform caller it has been handled completionHandler(); }
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; string titulo = string.Empty; //Extract the alert text // NOTE: If you're using the simple alert by just specifying // " aps:{alert:"alert msg here"} ", this will work fine. // But if you're using a complex alert with Localization keys, etc., // your "alert" object from the aps dictionary will be another NSDictionary. // Basically the JSON gets dumped right into a NSDictionary, // so keep that in mind. if (aps.ContainsKey(new NSString("alert"))) { alert = (aps[new NSString("alert")] as NSString).ToString(); titulo = (aps[new NSString("title")] as NSString).ToString(); } //If this came from the ReceivedRemoteNotification while the app was running, // we of course need to manually process things like the sound, badge, and alert. if (!fromFinishedLaunching) { UIAlertView avAlert = new UIAlertView("Notificación", alert, null, null, null); avAlert.AddButton("Ver detalles"); avAlert.AddButton("Cancelar"); avAlert.Show(); avAlert.Clicked += (sender, args) => { if (args.ButtonIndex == 0) { var storyboard = UIStoryboard.FromName("MainUniversal", null); var viewControllerActual = this.Window.RootViewController; while (viewControllerActual.PresentedViewController != null) { viewControllerActual = viewControllerActual.PresentedViewController; } NotificacionViewController notificacion = storyboard.InstantiateViewController("NotificacionView") as NotificacionViewController; if (notificacion != null) { notificacion.titulos = titulo; notificacion.descripciones = alert; viewControllerActual.ShowViewController(notificacion, viewControllerActual); } } }; } else { var storyboard = UIStoryboard.FromName("MainUniversal", null); var viewControllerActual = this.Window.RootViewController; while (viewControllerActual.PresentedViewController != null) { viewControllerActual = viewControllerActual.PresentedViewController; } NotificacionViewController notificacion = storyboard.InstantiateViewController("NotificacionView") as NotificacionViewController; if (notificacion != null) { notificacion.titulos = titulo; notificacion.descripciones = alert; viewControllerActual.ShowViewController(notificacion, viewControllerActual); } //NotificacionViewController.titulo = alert; //NotificacionViewController.descripcion = alert; //try //{ // viewControllerActual.PresentViewController(storyboard.InstantiateViewController("NavigationNotification"), true, null); //} //catch (Exception ex) //{ //} } } }