private static void HandleNotificationAction(ApnsNotificationActionEvent actionEvent) { if (actionEvent.NotificationInfo.GetValue<string>("notificationType") != "SIMPLEPUSHMSG") { return; } var option1 = actionEvent.NotificationInfo.GetValue<string>("lbl1"); var action1 = actionEvent.NotificationInfo.GetValue<string>("act1"); var data1 = actionEvent.NotificationInfo.GetValue<string>("link1"); bool hasAction2 = actionEvent.NotificationInfo.ContainsKey("lbl2"); var option2 = hasAction2 ? actionEvent.NotificationInfo.GetValue<string>("lbl2") : String.Empty; var action2 = hasAction2 ? actionEvent.NotificationInfo.GetValue<string>("act2") : String.Empty; var data2 = hasAction2 ? actionEvent.NotificationInfo.GetValue<string>("link2") : String.Empty; var wasOption1 = actionEvent.Action.ToLowerInvariant() == option1.ToLowerInvariant(); var userAction = wasOption1 ? (action1 == "Dismiss" ? "Dismissed" : "Button1") : (action2 == "Dismiss" ? "Dismissed" : "Button2"); var buttonDescription = String.Format("{0}|{1}", option1, option2); var interactionType = actionEvent.NotificationInfo.GetValue<string>("inttype"); var messageId = Guid.Parse(actionEvent.NotificationInfo.GetValue<string>("msgid")); var action = wasOption1 ? action1 : action2; var data = wasOption1 ? data1 : data2; DonkyCore.Instance.GetService<IPushMessagingManager>().HandleInteractionResultAsync(messageId, interactionType, buttonDescription, userAction, action, data).ExecuteInBackground(); }
public static void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) { var state = UIApplication.SharedApplication.ApplicationState; Logger.Instance.LogDebug("DidReceiveRemoteNotification, state: {0}", state); SetLaunchState(state, userInfo); // If we have received a 'single button' push and were lauched from the notification then handle the action if (state != UIApplicationState.Active && userInfo.ContainsKey("act1")) { var label = userInfo.GetValue<string>("lbl1"); var localEvent = new ApnsNotificationActionEvent(label, userInfo, new Action(() => completionHandler(UIBackgroundFetchResult.NoData))); DonkyCore.Instance.PublishLocalEvent(localEvent, Module); } else { DonkyCore.Instance.PublishLocalEvent(new ApnsNotificationReceivedEvent(userInfo, completionHandler), Module); } }