Push payload is not present on notification tap

I am checking if the user taps on the firebase push notification and get the payload.

override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
os_log("notification tapped %{public}@", log: OSLog.push, type: .info, userInfo)
handleNotificationPayload(userInfo as! [String: AnyObject])
setFlutterLinkClickedVariable()
}

My use case is in app terminated state when push notification is tapped, get the link from payload and navigate to corresponding screen based on the link. This is working when there is only one push notification. When there are multiple push notifications with different links in the payload, only the first notification I tap works. Rest of the notifications just launches the app and does not navigate because the link is not set.

I am getting the link from the payload and invoking flutter code which sets the link in the user defaults (shared preferences) and when the app launches in the home screen it checks for this variable and navigates accordingly.

func handleNotificationPayload(_ payload: [String: AnyObject]) {
if let link = payload["link"] as? String {
setFlutterLinkVariable(link)
}
}
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
os_log("app did receive remote notification %{public}@", log: OSLog.push, type: .info, userInfo)
handleNotificationPayload(userInfo as! [String : AnyObject])
completionHandler(.newData)
}

Currently when there is only one push notification it works because the link is set from the above method. The click delegate is not calling. I did set the delegate in application(:didFinishLaunchingWithOptions).

UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()

How to solve this issue? Thanks.

I did set the delegate UNUserNotificationCenter.current().delegate = self in application(:didFinishLaunchingWithOptions ..).

That's expected. The os is getting launched only for the notification that was tapped on.

Beyond that you can use this API: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/getdeliverednotifications(completionhandler:)

to query all delivered notifications and then process those. That said I recommend against processing delivered notifications. It's not the users's intent to interact with the rest. At best you should just log them.

Like imagine if each notification caused a navigation to a certain part of your app. Do you want to process and navigate 5 notifications at once?!

Push payload is not present on notification tap
 
 
Q