Skip to content

Commit

Permalink
TF-2871 Add adr for push notification click logic on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jun 7, 2024
1 parent eaba4b8 commit 38f9e74
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/adr/0048-push-notification-click-logic-on-ios.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 38. 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(CoreUtils.USER_CLICK_NOTIFICATION_IN_FOREGROUND_METHOD_CALL_NAME, 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 CoreUtils.GET_REMOTE_NOTIFICATION_PAYLOAD_METHOD_CALL_NAME:
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.

0 comments on commit 38f9e74

Please sign in to comment.