From 9e753768ccbf3d37f1fe3f8504039e4448fa37c2 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 2 Jul 2024 14:31:17 +0700 Subject: [PATCH] TF-2871 Add `adr` for push notification click logic on iOS --- ...y-one-pdf-in-dart-side-in-only-web-app.md} | 2 +- ...-android-notification-permission-check.md} | 2 +- ...51-push-notification-click-logic-on-ios.md | 79 +++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) rename docs/adr/{0048-view-one-by-one-pdf-in-dart-side-in-only-web-app.md => 0049-view-one-by-one-pdf-in-dart-side-in-only-web-app.md} (94%) rename docs/adr/{0049-android-notification-permission-check.md => 0050-android-notification-permission-check.md} (94%) create mode 100644 docs/adr/0051-push-notification-click-logic-on-ios.md diff --git a/docs/adr/0048-view-one-by-one-pdf-in-dart-side-in-only-web-app.md b/docs/adr/0049-view-one-by-one-pdf-in-dart-side-in-only-web-app.md similarity index 94% rename from docs/adr/0048-view-one-by-one-pdf-in-dart-side-in-only-web-app.md rename to docs/adr/0049-view-one-by-one-pdf-in-dart-side-in-only-web-app.md index f1315ded2..ecaa7d286 100644 --- a/docs/adr/0048-view-one-by-one-pdf-in-dart-side-in-only-web-app.md +++ b/docs/adr/0049-view-one-by-one-pdf-in-dart-side-in-only-web-app.md @@ -1,4 +1,4 @@ -# 48. View one-by-one PDF in Dart side in only Web app +# 49. View one-by-one PDF in Dart side in only Web app Date: 2024-05-17 diff --git a/docs/adr/0049-android-notification-permission-check.md b/docs/adr/0050-android-notification-permission-check.md similarity index 94% rename from docs/adr/0049-android-notification-permission-check.md rename to docs/adr/0050-android-notification-permission-check.md index dc7e475f4..1c22bf97c 100644 --- a/docs/adr/0049-android-notification-permission-check.md +++ b/docs/adr/0050-android-notification-permission-check.md @@ -1,4 +1,4 @@ -# 48. Notification setting +# 50. Android notification permission check Date: 2024-06-07 diff --git a/docs/adr/0051-push-notification-click-logic-on-ios.md b/docs/adr/0051-push-notification-click-logic-on-ios.md new file mode 100644 index 000000000..bba139562 --- /dev/null +++ b/docs/adr/0051-push-notification-click-logic-on-ios.md @@ -0,0 +1,79 @@ +# 51. Push notification click logic on iOS + +Date: 2024-06-07 + +## Status + +Accepted + +## Context + +On iOS, we use `Notification Service Extension` [NSE](https://developer.apple.com/documentation/usernotifications/modifying-content-in-newly-delivered-notifications) to modify email content first when displaying push notifications to users. +- In NSE we have implemented getting `new email list` based on `EmailDeliveryState` sent from FCM. +- NSE only modifies and displays 1 notification, so we will display the notification for the last email in the list via NSE (is called `RemoteNotification`). +For the remaining emails we will use [UNUserNotificationCenter](https://developer.apple.com/documentation/usernotifications/unusernotificationcenter) to automatically display notifications (is called `LocalNotification`). + +## Decision + +Brief the logic flows when clicking notifications: + +1. Foreground/Background state + +- When clicking on notifications (both LocalNotification and RemoteNotification) the `didReceive` function of `UNUserNotificationCenter` in `AppDelegate` will be called. + +```swift + override func userNotificationCenter( + _ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void + ) {} +``` + +`response.notification.request.content.userInfo` is the contents of the push payload notification. +We use `FlutterMethodChannel` to pass `UserInfo` from iOS native code to Flutter dart code + +```swift + self.notificationInteractionChannel?.invokeMethod("current_email_id_in_notification_click_on_foreground", arguments: response.notification.request.content.userInfo) +``` + +2. Terminated state + +- With `RemoteNotification`, we will get the push notification payload through `launchOptions?[.remoteNotification]` in the `didFinishLaunchingWithOptions` function of `AppDelegate` + +```swift +override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? +) -> Bool {} +``` + +Save it in a `remoteNotificationPayload` variable in memory and use `FlutterMethodChannel` to retrieve it every time you open the app. + +```swift +self.notificationInteractionChannel?.setMethodCallHandler { (call, result) in + switch call.method { + case "current_email_id_in_notification_click": + result(self.remoteNotificationPayload) + self.remoteNotificationPayload = nil + default: + break + } +} +``` + +- As for `LocalNotification`, we will receive the push notification payload at the `didReceive` function of `UNUserNotificationCenter` (similar to `Foreground/Background state`) + +```swift + override func userNotificationCenter( + _ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void +) { + self.remoteNotificationPayload = response.notification.request.content.userInfo + } +``` + +## Consequences + +- The application is correctly adjusted to the detailed screen email when clicking on the notification. +- Any changes to the click push notification logic must be updated in this ADR.