Opening specific view with navigation controller from push notication

Related searches

Im trying to open a certain view from a push notification but i keep losing the nav bar and the back and next references. this what my storyboard looks like this (with the view i want to open)

this is what i have in my AppDelagate:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "notification") as? NotificationViewController
            self.window?.rootViewController = vc

What you're doing is completely replacing the root view controller of your application, this means that all the current UI will be discarded.

What you should do instead is to use your knowledge of your application to direct it to the new content. For example, if your root view controller is a navigation controller, you can cast rootViewController to a nav controller and push it (this will fail if your root view controller is something else, like a tab bar controller).

guard let vc = storyboard.instantiateViewController(withIdentifier: "notification") as? NotificationViewController else {
  fatalError("Main Storyboard doesn't have a notification controller")
guard let nav = self.window?.rootViewController as? UINavigationController else {
  return //handle unexpected state
nav.push(vc, animated: true)

Another option would be to embed your notification controller into a navigation controller, add a Close button, and present it modally, that way you can present it on top of rootViewController no matter what that controller is.

Open app in specific view when push notification is tapped (iOS 13+), Example with tab bar controllers and navigation controllers. Say your app flow is like this, a tab bar controller as the initial view controller and� Frist, place a disconnected view controller with the view that you want in the storyboard, give the view controller an identifier, something like "My Push Notification View" In didFinishLaunchingWithOptions:, You can get to the rootViewController from the app delegate. This controller will be the navigation controller.

As we can see in the screenshot your provided, the application's root view controller is the UINavigationController instance.

And according to that, let me offer the next code:

func handleNotification(){
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        guard let vc = storyboard.instantiateViewController(withIdentifier: "notification") as? NotificationViewController else{
            debugPrint("NotificationViewController with identifier 'notification' not found")

        guard let navVC = self.window?.rootViewController as? UINavigationController else{
            debugPrint("RootViewController is not an UINavigationController")

        navVC.pushViewController(vc, animated: true) //perhaps your will prefer to use false

Beside that, you can use more flexible implementation.

In your AppDelegate post a (NS)Notification when notification intercepted, the relevant view-controller(s) observe the notification, and act when notification broadcasted.

You can also set an identifier to the segue and invoke performSegue method from the observing view-controller

How to open specific view controller when push notification received , When you app is in closed state you should check for launch option in " func application(_ application: UIApplication,� (If you're searching for how to open specific view controller when a push notification is tapped, the answer is here) How to make the app open a specific view controller when user tap on push notification? like when you tap the notification in twitter app, it brings you to the specific tweet. TL;DR: Jump to the final code

You can set from storyboard -> add view controller -> Embed in navigation controller -> set second view controller -> Attach seque between that controllers. You will see same view controllers like that image .

How to open a view controller on click a notification?, Hello - basically, given push notification payloads are in JSON form, you I discuss opening a specific view controller based on a notification, yes. that view controller directly, and you're not really in a navigation stack to it. After I click the push notifications, I want to go to a specific view controller, how can I do that? _ = OneSignal(launchOptions: launchOptions, appId: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba") { (message, additionalData, isActive) in NSLo

Opening viewcontroller from push notification : iOSProgramming, I know that this code makes the rootview my Chat but if I do this then I do not have my back button that is provided to me from my navigation controller and view� If we click on the debug hierachy button in Xcode while the app is running, we can see the 3D arrangement of the view controllers and views. Notice that UIWindow is on the furthest back in the hierachy, the tab bar controller is stacked on top of it, and then the navigation controller, and finally the specific view controller.

iOS Swift: Pushing two view controllers when app launched from , Open app in specific view when user taps on push notification with , To do this you need to set an identifier for each ViewController that your app may be opened� View Controller will have a current profile type and a mechanism to switch between profiles. I am not using any software design patterns because this is not the part of this tutorial.

My problem is when app is active or background it is open specific view controller but also showing previous open view controller in top design in back. Suppose I am using my app and viewController1 is currently open and I got an notification in Notification center and I click on notification to open Viewcontroller2.

  • you should embed it in a navigation controller
  • this gives me a new navigation controller, which i cant use the back button to return to the previous view.
  • You can hide it left bar button