public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var userInfo = response.Notification.Request.Content.UserInfo as NSDictionary; var aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary; var alert = aps.ObjectForKey(new NSString("alert")) as NSDictionary; var dictionary = alert.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString()); var type = string.Empty; var id = string.Empty; if (dictionary.ContainsKey(AppConstants.TYPE_VALUE)) { type = dictionary[AppConstants.TYPE_VALUE]; } if (dictionary.ContainsKey(AppConstants.ID_VALUE)) { id = dictionary[AppConstants.ID_VALUE]; } //(App.Current.MainPage as MainPage)?.Navigation.PushAsync(new SecondPage(type)); App.Current.MainPage.Navigation.PushAsync(new SecondPage(type, id)); Debug.WriteLine(type); }
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(); }
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { int routineIdx = int.Parse(notification.Request.Content.UserInfo["routineNum"].ToString()); string routineId = notification.Request.Content.UserInfo["routineId"].ToString(); bool isRoutineComplete = false; if (routineIdx < App.User.routines.Count && App.User.routines[routineIdx].id == routineId) { isRoutineComplete = App.User.routines[routineIdx].isComplete; } else { foreach (routine routine in App.User.routines) { if (routine.id == routineId) { isRoutineComplete = App.User.routines[routineIdx].isComplete; } } } DependencyService.Get <INotificationManager>().ReceiveNotification(notification.Request.Content.Title, notification.Request.Content.Body, !isRoutineComplete); // alerts are always shown for demonstration but this can be set to "None" // to avoid showing alerts if the app is in the foreground if (isRoutineComplete) { completionHandler(UNNotificationPresentationOptions.None); } else { completionHandler(UNNotificationPresentationOptions.Alert); } }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var actionSetId = response.Notification.Request.Content.CategoryIdentifier; var actionSet = _actionRegistrars.FirstOrDefault(r => r.ActionSetId == actionSetId); string actionIdentifier = response.ActionIdentifier; if (response.IsDismissAction) { actionIdentifier = ActionIdentifiers.Dismiss; } if (response.IsDefaultAction) { actionIdentifier = ActionIdentifiers.Default; } var action = actionSet?.RegisteredActions.FirstOrDefault(s => s.Id == actionIdentifier); action?.Action(new LocalNotificationArgs { Parameter = response.Notification.Request.Content.UserInfo[LocalNotificationActionParameterKey]?.ToString(), TimestampUtc = DateTime.UtcNow }); completionHandler(); }
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { Debug.WriteLine($"{TAG} WillPresentNotification {notification?.Request?.Content?.UserInfo}"); OnMessageReceived(notification?.Request?.Content?.UserInfo); completionHandler(UNNotificationPresentationOptions.Alert); }
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { // Timer here for a timeout since no Toast Dismissed Event (7 seconds til auto dismiss) var timer = NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(7), (nsTimer) => { if (_cancel || !_allowTapInNotificationCenter) { _action(_id, new NotificationResult() { Action = NotificationAction.Timeout }); } if (_cancel) // Clear notification from list { UNUserNotificationCenter.Current.RemoveDeliveredNotifications(new string[] { _id }); } nsTimer.Invalidate(); }); if (_previousDelegate != null) { _previousDelegate.WillPresentNotification(center, notification, completionHandler); } else { // Shows toast on screen completionHandler(UNNotificationPresentationOptions.Alert); } }
//アクション public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { // Take action based on Action ID switch (response.ActionIdentifier) { case "reply": //Replyボタンを押下した場合の動作を記述する break; default: // Take action based on identifier if (response.IsDefaultAction) { // デフォルトアクションを記述する } else if (response.IsDismissAction) { // キャンセルした場合 } break; } // Inform caller it has been handled completionHandler(); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var userInfo = response.Notification.Request.Content.UserInfo; ProcessNotification(userInfo, false); completionHandler(); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { // I Clicked it :) _Action(_Id, new NotificationResult { Action = NotificationAction.Clicked }); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { // Take action based on Action ID switch (response.ActionIdentifier) { case "reply": // Do something Console.WriteLine("Received the REPLY custom action."); break; default: // Take action based on identifier if (response.IsDefaultAction) { // Handle default action... Console.WriteLine("Handling the default action."); } else if (response.IsDismissAction) { // Handle dismiss action Console.WriteLine("Handling a custom dismiss action."); } break; } // Inform caller it has been handled completionHandler(); }
public override void WillPresentNotification( UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { completionHandler(UNNotificationPresentationOptions.Alert); }
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { System.Console.WriteLine(notification.Request.Content.UserInfo); var notifications = UNNotificationPresentationOptions.Alert; completionHandler(notifications); }
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")] //does it come after autologin? public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action //called when app is in background, and user taps on notification completionHandler) { completionHandler(); NSDictionary userInfo = response.Notification.Request.Content.UserInfo; CommonMethods c = new CommonMethods(null); BaseActivity context = CommonMethods.GetCurrentViewController(); CommonMethods.LogStatic("DidReceiveNotificationResponse " + userInfo.ToString().Replace(Environment.NewLine, " ") + " logged in " + c.IsLoggedIn() + " context " + context); if (userInfo != null && userInfo.ContainsKey(new NSString("aps"))) { int senderID = ((NSNumber)userInfo.ObjectForKey(new NSString("fromuser"))).Int32Value; int targetID = ((NSNumber)userInfo.ObjectForKey(new NSString("touser"))).Int32Value; if (targetID != Session.ID) { return; } IntentData.senderID = senderID; if (!(context is ChatOneActivity)) { CommonMethods.OpenPage("ChatOneActivity", 1); } //otherwise foreground notification will refresh the page } }
/// <inheritdoc /> public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { try { // Take action based on identifier if (!response.IsDefaultAction) { return; } var dictionary = response.Notification.Request.Content.UserInfo; if (!dictionary.ContainsKey(LocalNotificationService.ExtraReturnData)) { return; } var subscribeItem = new LocalNotificationTappedEvent { Data = dictionary[LocalNotificationService.ExtraReturnData].ToString() }; MessagingCenter.Send(subscribeItem, typeof(LocalNotificationTappedEvent).FullName); } catch (Exception ex) { Debug.WriteLine(ex); } }
public override async void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { if (this.sdelegate.Value == null) { return; } var notification = response.Notification.Request.FromNative(); if (response is UNTextInputNotificationResponse textResponse) { await Log.SafeExecute(async() => { var shinyResponse = new NotificationResponse(notification, textResponse.ActionIdentifier, textResponse.UserText); await this.sdelegate.Value.OnEntry(shinyResponse); }); } else { await Log.SafeExecute(async() => { var shinyResponse = new NotificationResponse(notification, response.ActionIdentifier, null); await this.sdelegate.Value.OnEntry(shinyResponse); }); } completionHandler(); }
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { // Tell system to display the notification anyway or use // `None` to say we have handled the display locally. completionHandler(UNNotificationPresentationOptions.Alert); }
/// <summary> /// Method for processing the user's response to a delivered notification. /// </summary> /// <param name="center">The shared user notification center object that received the notification.</param> /// <param name="response">The user's response to the notification.</param> /// <param name="completionHandler">The action to execute when you have finished processing the user's response.</param> public static void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { if (Current is NotifoMobilePushImplementation notifoMobilePush) { notifoMobilePush.DidReceiveNotificationResponse(center, response, completionHandler); } }
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { var title = notification.Request.Content.Title; var body = notification.Request.Content.Body; debugAlert(title, body); }
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var eventId = response.Notification.Request.Content.UserInfo[NotificationServiceIos.CalendarEventIdKey] as NSString; if (response.IsCustomAction) { switch (response.ActionIdentifier.ToString()) { case NotificationServiceIos.OpenAndCreateFromCalendarEvent: openAndStartTimeEntryFromCalendarEvent(eventId.ToString(), completionHandler); break; case NotificationServiceIos.OpenAndNavigateToCalendar: openAndNavigateToCalendar(completionHandler); break; case NotificationServiceIos.StartTimeEntryInBackground: startTimeEntryInBackground(eventId.ToString(), completionHandler); break; } } else if (response.IsDefaultAction) { openAndStartTimeEntryFromCalendarEvent(eventId.ToString(), completionHandler); } }
/// <summary> /// Called just prior to a notification being presented while the app is in the foreground. /// </summary> /// <param name="center"></param> /// <param name="notification"></param> /// <param name="completionHandler"></param> public override async void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { string identifier = notification?.Request?.Identifier; SensusServiceHelper.Get().Logger.Log("Notification delivered: " + (identifier ?? "[null identifier]"), LoggingLevel.Normal, GetType()); // if the notification is for a callback, service the callback and do not show the notification. we use the local // notification loop to schedule callback events and don't want to display the messages when the app is foregrounded. NSDictionary notificationInfo = notification?.Request?.Content?.UserInfo; iOSCallbackScheduler callbackScheduler = SensusContext.Current.CallbackScheduler as iOSCallbackScheduler; if (callbackScheduler.IsCallback(notificationInfo)) { await callbackScheduler.RaiseCallbackAsync(notificationInfo); completionHandler?.Invoke(UNNotificationPresentationOptions.None); } else if (identifier == Notifier.PENDING_SURVEY_TEXT_NOTIFICATION_ID) { completionHandler?.Invoke(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound); } else if (identifier == Notifier.PENDING_SURVEY_BADGE_NOTIFICATION_ID) { completionHandler?.Invoke(UNNotificationPresentationOptions.Badge); } else { completionHandler?.Invoke(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound); } }
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var parameters = GetParameters(response.Notification.Request.Content.UserInfo); string?result = null; NotificationCategoryType catType = NotificationCategoryType.Default; if (response.IsCustomAction) { catType = NotificationCategoryType.Custom; } else if (response.IsDismissAction) { catType = NotificationCategoryType.Dismiss; } if (response is UNTextInputNotificationResponse textResponse) { result = textResponse.UserText; } var notificationResponse = new NotificationResponse(parameters, $"{response.ActionIdentifier}".Equals("com.apple.UNNotificationDefaultActionIdentifier", StringComparison.CurrentCultureIgnoreCase) ? string.Empty : $"{response.ActionIdentifier}", catType, result); _onNotificationAction?.Invoke(this, new PushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type, result)); CrossPushNotification.Current.NotificationHandler?.OnAction(notificationResponse); // Inform caller it has been handled completionHandler(); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var userInfo = response.Notification.Request.Content.UserInfo; NSString[] keys = new NSString[userInfo.Keys.Length]; int i; for (i = 0; i < userInfo.Keys.Length; i++) { if (userInfo.Keys[i] is NSString) { keys[i] = userInfo.Keys[i] as NSString; } else { i = int.MaxValue; } } if (i != int.MaxValue) { NSDictionary <NSString, NSObject> notif = new NSDictionary <NSString, NSObject>(keys, userInfo.Values); NITManager.DefaultManager.ProcessRecipeWithUserInfo(notif, (content, trackingInfo, error) => { if (content != null && content is NITReactionBundle) { //call the ParseContent to manage your notification } }); } }
public override int ScheduleLocalNotification(string body, int delay) { if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; UNMutableNotificationContent content = new UNMutableNotificationContent(); content.Body = body; content.Sound = UNNotificationSound.Default; UNTimeIntervalNotificationTrigger trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(delay, false); UNNotificationRequest request = UNNotificationRequest.FromIdentifier(StringIdentifierFromInt(LocalNotificationUid), content, trigger); center.AddNotificationRequest(request, (NSError error) => { if (error != null) { Console.WriteLine("Something went wrong:" + error); } }); } else { UILocalNotification localNotification = new UILocalNotification(); localNotification.FireDate = NSDate.FromTimeIntervalSinceNow(delay); localNotification.AlertBody = body; localNotification.TimeZone = NSTimeZone.DefaultTimeZone; localNotification.UserInfo = NSDictionary.FromObjectAndKey(NSNumber.FromInt32(LocalNotificationUid), new NSString(PWMLocalNotificationUidKey)); UIApplication.SharedApplication.ScheduleLocalNotification(localNotification); } return(LocalNotificationUid++); }
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: // Take action based on identifier if (response.IsDefaultAction) { // Handle default action... } else if (response.IsDismissAction) { // Handle dismiss action } break; } // Inform caller it has been handled completionHandler(); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { //if (App.badgeCount > 0) //{ // App.badgeCount = App.badgeCount - 1; // CrossBadge.Current.SetBadge(App.badgeCount); //} var aps = response.Notification.Request.Content.UserInfo. ObjectForKey(new NSString("aps")) as NSDictionary; var type = response.Notification.Request.Content.UserInfo. ObjectForKey(new NSString("gcm.notification.type")) as NSString; if (type == "5") { //MainTabbedPage._isAskMsg = true; //App.Current.MainPage = new NavigationPage(new MainTabbedPage()); } else if (type == "6") //quiz notification { //MainTabbedPage._isAskMsg = false; //App.Current.MainPage = new NavigationPage(new MainTabbedPage()); } else { //App.Current.MainPage.Navigation.PushAsync(new AlertsPage()); } completionHandler(); }
//Remote notification support private void RegisterForNotifications(UIApplication application) { if (application.IsRegisteredForRemoteNotifications) { var types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(types, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } else { application.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound); } UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.Delegate = this; center.RequestAuthorization(UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Alert, (success, error) => { if (error != null) { Debug.WriteLine(String.Format("Error registering for UserNotifications {0}", error)); } else { Debug.WriteLine("Registered for UserNotifications"); } }); }
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { //triggered when app is in foreground //var userInfo = notification.Request.Content.UserInfo; //userInfo.NotificationObject completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound); }
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { var parameters = GetParameters(response.Notification.Request.Content.UserInfo); var catType = NotificationCategoryType.Default; if (response.IsCustomAction) { catType = NotificationCategoryType.Custom; } else if (response.IsDismissAction) { catType = NotificationCategoryType.Dismiss; } var ident = $"{response.ActionIdentifier}".Equals("com.apple.UNNotificationDefaultActionIdentifier", StringComparison.CurrentCultureIgnoreCase) ? string.Empty : $"{response.ActionIdentifier}"; var notificationResponse = new NotificationResponse(parameters, ident, catType); if (string.IsNullOrEmpty(ident)) { _onNotificationOpened?.Invoke(this, new FirebasePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type)); CrossFirebaseEssentials.Notifications.NotificationHandler?.OnOpened(notificationResponse); } else { _onNotificationAction?.Invoke(this, new FirebasePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type)); // CrossFirebasePushNotification.Current.NotificationHandler?.OnOpened(notificationResponse); } // Inform caller it has been handled completionHandler(); }
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler) { // Do your magic to handle the notification data Console.WriteLine(notification.Request.Content.UserInfo); Debug.WriteLine("WillPresentNotification"); var parameters = GetParameters(notification.Request.Content.UserInfo); _onNotificationReceived?.Invoke(CrossFirebaseEssentials.Notifications, new FirebasePushNotificationDataEventArgs(parameters)); CrossFirebaseEssentials.Notifications.NotificationHandler?.OnReceived(parameters); if (parameters.TryGetValue("priority", out var priority) && ($"{priority}".ToLower() == "high" || $"{priority}".ToLower() == "max")) { if (!CurrentNotificationPresentationOption.HasFlag(UNNotificationPresentationOptions.Alert)) { CurrentNotificationPresentationOption |= UNNotificationPresentationOptions.Alert; } } else if ($"{priority}".ToLower() == "default" || $"{priority}".ToLower() == "low" || $"{priority}".ToLower() == "min") { if (CurrentNotificationPresentationOption.HasFlag(UNNotificationPresentationOptions.Alert)) { CurrentNotificationPresentationOption &= ~UNNotificationPresentationOptions.Alert; } } completionHandler(CurrentNotificationPresentationOption); }
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { try { // Take action based on Action ID switch (response.ActionIdentifier) { case "reply": // Do something Console.WriteLine("Received the REPLY custom action."); break; default: // Take action based on identifier ResetNotificationBadge(); ProcessDefaultNotificationAction(response); break; } } catch (Exception e) { LogHelper.LogUserMessage("NOTIFICATIONPENDING_FAILED", e.Message); } // Inform caller it has been handled completionHandler(); }
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler) { // Do something with the notification Console.WriteLine("Active Notification: {0}", notification); // Tell system to display the notification anyway or use // `None` to say we have handled the display locally. completionHandler(UNNotificationPresentationOptions.Alert); }