When the app is in terminate state and I receive a push notification. Which if I view I want the app to load normally but it should present a viewController
over the rootViewController
for which I've added a close button and whenever i will tap this button i want simply dismiss this viewController
.
In the method which is called when I open the app from notification I've done this:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let tabBarController = self.window!.rootViewController as! UITabBarController
self.window?.rootViewController = tabBarController
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationVC") as! NotificationsViewController
window?.makeKeyAndVisible()
window?.rootViewController?.present(apptVC, animated: true, completion: nil)
completionHandler()
}
}
But unfortunately when I do that the app crashes. I've implemented push notification using firebase
. I want the app to run normally like it does it's just like presenting a view controller over the root view controller on launch when user is coming from notification.