我正在使用FCM和iOS推送通知。当用户点击推送通知时,我该如何导航到特定的导航链接?非常感谢您的帮助!
我知道我将在这个函数中处理推送通知的点击。
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()
}
我还有一个@EnvironmentObject
,用于控制哪个tabItem处于活动状态以及哪个NavigationLink已经打开。
我如何在我的UNNotificationResponse didReceive
函数中访问这个EnvironmentObject?