I recently encountered a problem with freshchat and firebaseMessaging (FCM).
When I sent a push notification with a deep link, my fcm code (onMessageOpenedApp) was not triggered when I clicked on the notification only with iOS.
Not having seen any problem on this subject, I post just in case the solution for people who have this problem in the future
I hope this will be useful to you 😊
The freshchat library overloaded native ios functions (userNotificationCenter) and we simply added a call to the parent constructor
super.userNotificationCenter(center, willPresent: willPresent, withCompletionHandler: withCompletionHandler)
The code below (AppDelegate.swift)
import Flutter
import Firebase
import UserNotifications
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
let viewController = UIApplication.shared.windows.first!.rootViewController as! UIViewController
window = FreshchatSdkPluginWindow(frame: UIScreen.main.bounds)
window.rootViewController = viewController
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
UIApplication.shared.registerForRemoteNotifications()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FreshchatSdkPlugin().setPushRegistrationToken(deviceToken)
}
//@available(iOS 10.0, *)
override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent: UNNotification, withCompletionHandler: @escaping (UNNotificationPresentationOptions)->()) {
let freshchatSdkPlugin = FreshchatSdkPlugin()
if freshchatSdkPlugin.isFreshchatNotification(willPresent.request.content.userInfo) {
freshchatSdkPlugin.handlePushNotification(willPresent.request.content.userInfo)
} else {
super.userNotificationCenter(center, willPresent: willPresent, withCompletionHandler: withCompletionHandler)
}
}
//@available(iOS 10.0, *)
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive: UNNotificationResponse, withCompletionHandler: @escaping ()->()) {
let freshchatSdkPlugin = FreshchatSdkPlugin()
if freshchatSdkPlugin.isFreshchatNotification(didReceive.notification.request.content.userInfo) {
freshchatSdkPlugin.handlePushNotification(didReceive.notification.request.content.userInfo) //Handled for freshchat notifications
withCompletionHandler()
} else {
super.userNotificationCenter(center, didReceive: didReceive, withCompletionHandler: withCompletionHandler)
}
}
}```