I am using FCM with my ios push notification. How can I navigate to a specific navigation link when the user taps the push notification. Thank you in advance for your help!
I understand that I will handle the push notification tap on this function.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID userNotificationCenterdidReceive response: \(messageID)")
}
// Print full message.
print(userInfo)
let application = UIApplication.shared
if(application.applicationState == .active){
print("user tapped the notification bar when the app is in foreground")
}
if(application.applicationState == .inactive)
{
print("user tapped the notification bar when the app is in background")
}
completionHandler()
}
I also have an @EnvironmentObject
that controls which tabItem is active and which NavigationLink is open.
How can I access this EnvironmentObject on my UNNotificationResponse didReceive function?
Assuming this callback is in AppDelegate, you can make AppDelegate owner of your shared object which is used as environment object, so you have access to it and in app delegate callbacks and in scene delegate to inject into content view.
Please see my proposed approach for similar scenario in App Delegate Accessing Environment Object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With