Связь между DidReceiveNotificationResponse в AppDelegate.cs и ViewController при нажатии уведомления ⇐ IOS
-
Гость
Связь между DidReceiveNotificationResponse в AppDelegate.cs и ViewController при нажатии уведомления
Я создаю подобные уведомления, когда пользователь входит в геозону.
UNMutableNotificationContent NotificationContent = новый UNMutableNotificationContent(); NotificationContent.Title = "Введенный регион"; NotificationContent.Body = "Вы ввели регион " + Fence.title + ". Нажмите здесь, чтобы зарегистрироваться."; RegisterNotification(notificationContent, "LocationStatus"); public static void RegisterNotification (UNMutableNotificationContent NotificationContent, строковый идентификатор) { Центр UNUserNotificationCenter = UNUserNotificationCenter.Current; NotificationContent.Sound = UNNotificationSound.Default; Запрос UNNotificationRequest = UNNotificationRequest.FromIdentifier(идентификатор, NotificationContent, ноль); center.AddNotificationRequest(запрос, (NSError obj) => { }); } Теперь, когда пользователь нажимает уведомление, я хочу связаться с ViewController и отправить объект Fence в ViewController, чтобы пользователь мог зарегистрироваться в этом месте.
Не знаю, как это сделать в iOS. В Android я использовал Intent и Extras, чтобы сделать то же самое.
Версия для Android:
string message = "Вы ввели " + k.title + ". Нажмите здесь, чтобы зарегистрироваться."; вар намерение = новое намерение (это, typeof (MainActivity)); Intent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop); если (действие!= ноль) { Intent.PutExtra("забор", Newtonsoft.Json.JsonConvert.SerializeObject(new FenceAction()) { действие = действие, публичный идентификатор = публичный идентификатор })); } вар pendingIntent = PendingIntent.GetActivity(this, 0, намерение, PendingIntentFlags.UpdateCurrent); Notification.Builder NotificationBuilder = новый Notification.Builder(это, NOTIFICATION_CHANNEL_ID) .SetSmallIcon(Resource.Drawable.notification) .SetContentTitle("Умный офис") .SetContentText(сообщение) .SetAutoCancel(истина) .SetContentIntent(pendingIntent) .SetOngoing(ложь); вар NotificationManager = (NotificationManager) GetSystemService (NotificationService); NotificationManager.Notify(NOTIFICATION_AlARM_ID, NotificationBuilder.Build()); защищенное переопределение void OnNewIntent(Intent e) { base.OnNewIntent(e); если (e.Extras != ноль) { строковый забор = e.Extras.GetString("забор"); если (!string.IsNullOrEmpty(забор)) { Действие LocationService.FenceAction = Newtonsoft.Json.JsonConvert.DeserializeObject(fence); ... } } } Я хочу сделать то же самое с iOS. Но не уверен, как это реализовать. Заранее спасибо.
Я создаю подобные уведомления, когда пользователь входит в геозону.
UNMutableNotificationContent NotificationContent = новый UNMutableNotificationContent(); NotificationContent.Title = "Введенный регион"; NotificationContent.Body = "Вы ввели регион " + Fence.title + ". Нажмите здесь, чтобы зарегистрироваться."; RegisterNotification(notificationContent, "LocationStatus"); public static void RegisterNotification (UNMutableNotificationContent NotificationContent, строковый идентификатор) { Центр UNUserNotificationCenter = UNUserNotificationCenter.Current; NotificationContent.Sound = UNNotificationSound.Default; Запрос UNNotificationRequest = UNNotificationRequest.FromIdentifier(идентификатор, NotificationContent, ноль); center.AddNotificationRequest(запрос, (NSError obj) => { }); } Теперь, когда пользователь нажимает уведомление, я хочу связаться с ViewController и отправить объект Fence в ViewController, чтобы пользователь мог зарегистрироваться в этом месте.
Не знаю, как это сделать в iOS. В Android я использовал Intent и Extras, чтобы сделать то же самое.
Версия для Android:
string message = "Вы ввели " + k.title + ". Нажмите здесь, чтобы зарегистрироваться."; вар намерение = новое намерение (это, typeof (MainActivity)); Intent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.ClearTop); если (действие!= ноль) { Intent.PutExtra("забор", Newtonsoft.Json.JsonConvert.SerializeObject(new FenceAction()) { действие = действие, публичный идентификатор = публичный идентификатор })); } вар pendingIntent = PendingIntent.GetActivity(this, 0, намерение, PendingIntentFlags.UpdateCurrent); Notification.Builder NotificationBuilder = новый Notification.Builder(это, NOTIFICATION_CHANNEL_ID) .SetSmallIcon(Resource.Drawable.notification) .SetContentTitle("Умный офис") .SetContentText(сообщение) .SetAutoCancel(истина) .SetContentIntent(pendingIntent) .SetOngoing(ложь); вар NotificationManager = (NotificationManager) GetSystemService (NotificationService); NotificationManager.Notify(NOTIFICATION_AlARM_ID, NotificationBuilder.Build()); защищенное переопределение void OnNewIntent(Intent e) { base.OnNewIntent(e); если (e.Extras != ноль) { строковый забор = e.Extras.GetString("забор"); если (!string.IsNullOrEmpty(забор)) { Действие LocationService.FenceAction = Newtonsoft.Json.JsonConvert.DeserializeObject(fence); ... } } } Я хочу сделать то же самое с iOS. Но не уверен, как это реализовать. Заранее спасибо.
Мобильная версия