title: SwiftUI - Open a specific View when user opens a Push Notification
body: <p>A have an app made in SwiftUI, with Parse used for DB.
  I'm some parts of the app i've integrated some cloud functions that send notifications (for example: when someone send's you a message, you will receive a push notification triggered by that cloud function).
  In the past days i'm struggling and searching for how to open a specific view when you press the Notification to open the app.
  I've found some solutions, but could not make them work.</p>
  <p>This is the code that i have so far :</p>
  <pre><code>class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -&gt; Bool {
          
          //Parse Intialization
          ...
          //notifications
          registerForPushNotifications()
          //Notification Badge
          UIApplication.shared.applicationIconBadgeNumber = 0
          // start notification while app is in Foreground
          UNUserNotificationCenter.current().delegate = self
          return true
      }
      
      // This function will be called right after user tap on the notification
      func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {
          print(&quot;app opened from PushNotification tap&quot;)
          UIApplication.shared.applicationIconBadgeNumber = 0
        completionHandler()
      }
  }
  
  @main
  struct MyApp: App {
      
      @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
      
      var body: some Scene {
          WindowGroup {
              ContentView(currentTab: Tab.home)
          }
      }
  }
  </code></pre>
  <p>The app prints &quot;app opened from PushNotification tap&quot;, but if I put a variable in AppDelegate and I listen for changes in ContentView with .onReceive or .onChange for that variable, nothing is hapenning</p>
  <pre><code>struct ContentView: View {
      @ObservedObject var appState = AppState()
      @State var currentTab : Tab
      @State var noReloadAddItemView = false
      var body: some View {
          TabView(selection: $appState.currentTab) {
              
              NavigationView {
                  HomeView(appState: appState, noReloadAddItemView: $noReloadAddItemView)
                  
              }
              .tabItem {
                  if appState.currentTab == .home {
                      Image(systemName: &quot;house.fill&quot;)
                  } else {
                      Image(systemName: &quot;house&quot;)
                  }
                  
                  Text(LocalizedStringKey(&quot;HomeTabMenu&quot;))
                  
              }.tag(Tab.home)
              
              NavigationView {
                  SearchView(appState: appState, noReloadAddItemView: $noReloadAddItemView)
              }
              .tabItem {
                  if appState.currentTab == .search {
                      Image(systemName: &quot;magnifyingglass.circle.fill&quot;)
                  } else {
                      Image(systemName: &quot;magnifyingglass&quot;)
                  }
                  Text(LocalizedStringKey(&quot;SearchTabMenu&quot;))
              }.tag(Tab.search)
              
              NavigationView {
                  AddItemView(appState: appState, noReloadAddItemView: $noReloadAddItemView)
              }
              .tabItem {
                  if appState.currentTab == .add {
                      Image(systemName: &quot;plus.circle.fill&quot;)
                  } else {
                      Image(systemName: &quot;plus.circle&quot;)
                  }
                  Text(LocalizedStringKey(&quot;SellTabMenu&quot;))
              }.tag(Tab.add)
              
              NavigationView {
                  ShoppingCartFavoritesView(appState: appState, noReloadAddItemView: $noReloadAddItemView)
              }
              .tabItem {
                  if appState.currentTab == .favorites {
                      Image(systemName: &quot;cart.fill&quot;)
                  } else {
                      Image(systemName: &quot;cart&quot;)
                  }
                  Text(LocalizedStringKey(&quot;CartTabMenu&quot;))
              }.tag(Tab.favorites)
              
              NavigationView {
                  ProfileView(appState: appState, noReloadAddItemView: $noReloadAddItemView)
              }
              .tabItem {
                  if appState.currentTab == .profile {
                      Image(systemName: &quot;person.fill&quot;)
                  } else {
                      Image(systemName: &quot;person&quot;)
                  }
                  Text(LocalizedStringKey(&quot;ProfileTabMenu&quot;))
              }.tag(Tab.profile)
          }
          .accentColor(Color(&quot;ColorMainDark&quot;))
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView(currentTab: Tab.home)
      }
  }
  
  class AppState: ObservableObject {
      @Published var currentTab : Tab = .home
  }
  
  enum Tab {
      case home, search, add, favorites, profile
  }
  </code></pre>