3

I have List in Content View & List is connected to Detail View by Navigation Link. I am using User Notifications with SwiftUI I want to automatically redirect to Detail View when tapped on Notification

From App Delegate:

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

        let application = UIApplication.shared

        // Show on Tap
        application.applicationIconBadgeNumber = 0

        if application.applicationState == .inactive {

            let detailView = DetailView(item: DummyData[1])

            if let window = UIApplication.shared.keyWindow {
                self.window = window
            }

            self.window?.rootViewController = UIHostingController(rootView: detailView)
            self.window?.makeKeyAndVisible()
        }

        completionHandler()
    }

This code is showing Detail View, but unable to Navigate through the app (Navigation View).

How to redirect to detail view when tapped on Notification like WhatsApp, Instagram using SwiftUI?

Dc7
  • 1,405
  • 1
  • 10
  • 16

1 Answers1

0

You need to have some tag/data for which detail view you want to to navigate to. Then you can use NavigationLink(_,destination:,tag:,selection:) inside your NavigationView, where selection is bound to that tag.

For a detailed explanation and example code, see https://nalexn.github.io/swiftui-deep-linking/ .

Yonat
  • 4,382
  • 2
  • 28
  • 37