Swiftui:当用户单击推送通知时,如何导航到特定的 NavigationLink?
Swiftui: How can I navigate to a specific NavigationLink when user clicks on push notification?
我在 ios 推送通知中使用 FCM。当用户点击推送通知时,如何导航到特定导航 link。预先感谢您的帮助!
我知道我会处理点击此功能的推送通知。
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?
假设这个回调在 AppDelegate 中,您可以让 AppDelegate 成为您用作环境对象的共享对象的所有者,这样您就可以访问它并在应用委托回调和场景委托中注入内容视图。
请参阅我在
中针对类似情况提出的方法
我在 ios 推送通知中使用 FCM。当用户点击推送通知时,如何导航到特定导航 link。预先感谢您的帮助!
我知道我会处理点击此功能的推送通知。
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?
假设这个回调在 AppDelegate 中,您可以让 AppDelegate 成为您用作环境对象的共享对象的所有者,这样您就可以访问它并在应用委托回调和场景委托中注入内容视图。
请参阅我在