TF-2384 Handle open email detailed when click notification on background mode

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 72db39c87dbd8f06bfbb417e4fed4d384da356ea)
This commit is contained in:
dab246
2023-12-25 00:03:48 +07:00
committed by Dat H. Pham
parent aac12f5731
commit 84b7239ad0
8 changed files with 98 additions and 12 deletions
+19
View File
@@ -7,12 +7,16 @@ import flutter_local_notifications
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
var notificationInteractionChannel: FlutterMethodChannel?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
createNotificationInteractionChannel()
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}
@@ -94,7 +98,13 @@ import flutter_local_notifications
}
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
TwakeLogger.shared.log(message: "AppDelegate::userNotificationCenter::didReceive::response: \(response)")
updateAppBadger(currentBadgeCount: UIApplication.shared.applicationIconBadgeNumber)
if let emailId = response.notification.request.content.userInfo[JmapConstants.EMAIL_ID] as? String {
self.notificationInteractionChannel?.invokeMethod("openEmail", arguments: emailId)
}
completionHandler()
}
}
@@ -124,4 +134,13 @@ extension AppDelegate {
private func isAppForegroundActive() -> Bool {
return UIApplication.shared.applicationState == .active
}
private func createNotificationInteractionChannel() {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
self.notificationInteractionChannel = FlutterMethodChannel(
name: "notification_interaction_channel",
binaryMessenger: controller.binaryMessenger
)
}
}