'How can i navigate to a specific screen while i tap on the push notificatios

I connected my project to firebase(FCM) for notifications. Iam getting notifications but i cant navigate to required screen while iam tapping on notifications. For me while i tap on notification if the app is on foreground its showing the same screen while app is in background its showing the tab screen which i gave. i want to navigate to specific screen like chats or alerts.

Programmatic Navigation after opening notification SwiftUI I tried this link code i didn't get the reqired solution.



Solution 1:[1]

You should add a delegate of UNUserNotificationCenterDelegate and implement two of its methods which are listed below.

     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            completionHandler([.alert,.badge,.sound])
        }
        func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            print(response.notification.request.content.userInfo)
           //Handle your tap here
            completionHandler()
            
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1