Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-3275 Fix FCM iOS foreground desync #3314

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ import flutter_local_notifications
}
if validateDisplayPushNotification(userInfo: notification.request.content.userInfo) {
completionHandler([.alert, .badge, .sound])
} else if UIApplication.shared.applicationState == .active {
let viewController = window?.rootViewController as! FlutterViewController
let fcmMethodChannel = FlutterMethodChannel(
name: CoreUtils.FCM_METHOD_CHANNEL_NAME,
binaryMessenger: viewController.binaryMessenger)
fcmMethodChannel.invokeMethod(
CoreUtils.FCM_ON_MESSAGE_METHOD_NAME,
arguments: notification.request.content.userInfo)
dab246 marked this conversation as resolved.
Show resolved Hide resolved

completionHandler([])
} else {
completionHandler([])
}
Expand Down
2 changes: 2 additions & 0 deletions ios/TwakeCore/Utils/CoreUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class CoreUtils {
static let NOTIFICATION_INTERACTION_CHANNEL_NAME = "notification_interaction_channel"
static let CURRENT_EMAIL_ID_IN_NOTIFICATION_CLICK_WHEN_APP_FOREGROUND_OR_BACKGROUND = "current_email_id_in_notification_click_when_app_foreground_or_background"
static let CURRENT_EMAIL_ID_IN_NOTIFICATION_CLICK_WHEN_APP_TERMINATED = "current_email_id_in_notification_click_when_app_terminated"
static let FCM_METHOD_CHANNEL_NAME = "plugins.flutter.io/firebase_messaging"
static let FCM_ON_MESSAGE_METHOD_NAME = "Messaging#onMessage"

func getCurrentDate() -> Date {
if #available(iOS 15, *) {
Expand Down
11 changes: 9 additions & 2 deletions ios/TwakeMailNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class NotificationService: UNNotificationServiceExtension {

private var handler: ((UNNotificationContent) -> Void)?
private var modifiedContent: UNMutableNotificationContent?
private var originalContent: UNNotificationContent = UNNotificationContent()

private lazy var keychainController = KeychainController(service: .sessions,
accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
handler = contentHandler
modifiedContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
originalContent = request.content

guard let payloadData = request.content.userInfo as? [String: Any],
!keychainController.retrieveSharingSessions().isEmpty else {
Expand Down Expand Up @@ -143,6 +145,7 @@ class NotificationService: UNNotificationServiceExtension {
self.modifiedContent?.body = message
self.modifiedContent?.badge = NSNumber(value: 1)
self.modifiedContent?.sound = .default
self.modifiedContent?.userInfo = ["data": originalContent.userInfo]
dab246 marked this conversation as resolved.
Show resolved Hide resolved
}

private func showModifiedNotification(title: String?,
Expand All @@ -155,7 +158,9 @@ class NotificationService: UNNotificationServiceExtension {
self.modifiedContent?.body = body ?? ""
self.modifiedContent?.badge = NSNumber(value: badgeCount)
self.modifiedContent?.sound = .default
self.modifiedContent?.userInfo = userInfo
var combinedUserInfo = userInfo
combinedUserInfo["data"] = originalContent.userInfo
self.modifiedContent?.userInfo = combinedUserInfo
dab246 marked this conversation as resolved.
Show resolved Hide resolved
dab246 marked this conversation as resolved.
Show resolved Hide resolved
}

private func showNewNotification(title: String?,
Expand All @@ -171,7 +176,9 @@ class NotificationService: UNNotificationServiceExtension {
content.body = body ?? ""
content.sound = .default
content.badge = NSNumber(value: badgeCount)
content.userInfo = userInfo
var combinedUserInfo = userInfo
combinedUserInfo["data"] = originalContent.userInfo
content.userInfo = combinedUserInfo

// Create a notification trigger
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
Expand Down
Loading