【发布时间】:2020-03-25 00:47:41
【问题描述】:
我在我的 ios 推送通知中使用 FCM。当用户点击推送通知时,我如何导航到特定的导航链接。提前感谢您的帮助!
我知道我将处理此功能上的推送通知点击。
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?
【问题讨论】:
-
你能展示你的代码吗?
-
@Asperi,我更新了我的答案,谢谢你的回复
-
假设此回调在 AppDelegate 中,您可以让 AppDelegate 成为您的共享对象的所有者,该对象用作环境对象,因此您可以访问它以及在应用程序委托回调和场景委托中注入内容看法。以下内容可能会有所帮助App Delegate Accessing Environment Object
标签: push-notification firebase-cloud-messaging swiftui