1

I'd like pressing a notification to open up a certain page in the SwiftUI app. I'm able to trigger the print statement "notification was tapped" when the notification is tapped by having this code in the AppDelegate.swift

extension AppDelegate: UNUserNotificationCenterDelegate {
      func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            completionHandler([.alert, .sound, .badge])
      }

      func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            print("notification was tapped")
            // add code to open specific swiftUI view here!
            completionHandler()
      }
}

How can control the view that will be opened from the AppDelegate.swift?

Joshua Segal
  • 541
  • 1
  • 7
  • 19
  • It can be done like in solutions provided in [App Delegate Accessing Environment Object](https://stackoverflow.com/questions/59379898/app-delegate-accessing-environment-object) – Asperi Jun 18 '20 at 13:26

0 Answers0