I am using SwiftUI 2.0 and I am trying to implement firebase push notifications. In new SwiftUI app structure, there's no AppDelegate and SceneDelegate, so I created AppDelegate class. I managed receiving notifications but I cant go to a specific view on notification click. Here is my code:
@main
struct swiftUiApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
And AppDelegate extension:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let orders = Orders()
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
if(userInfo["gcm.notification.type"] != nil){
if(userInfo["gcm.notification.type"] as! String == "order"){
//here I need to navigate to OrderView
}
}
}
UNUserNotificationCenter.current().delegate = self
intoapplicationDidFinishLaunching
inside. – Adrenal