Prior to iOS 13, navigation controllers and root views were defined in AppDelegate. With iOS 13 however, Apple introduced SceneDelegate, which takes over the handling of these view functions. However, AppDelegate still handles things such as Local Notification Handling. See this answer for some code that outlines these changes for root views.
If I wanted a view to be pushed when a user taps a local notification, I would do the something like the following in AppDelegate:
extension AppDelegate: UNUserNotificationCenterDelegate {
var navigationController: UINavigationController?
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == UNNotificationDefaultActionIdentifier { //User taps notification
let vc = MyViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
However, since the root navigation controller for my project can now be defined in SceneDelegate as of iOS 13, I can't seem to figure out how to push a view within a navigation controller managed by SceneDelegate instead of AppDelegate.
Push notifications provide the capability to communicate brief, yet important alerts to your mobile app users. CleverTap’s rich segmentation and powerful infrastructure lets you send time-sensitive, relevant, and personalized push messages on a large-scale.
Not only is it nice to let users know about something that may interest them, be it a new album being released, a sale or other limited-time-only deal, or that one of their friends sent them a message, but push notifications are proven to help boost user interaction and create a better overall user experience.
Additionally, when calling Notifications.requestPermissionsAsync () on the simulator, it will resolve immediately with undetermined as the status, regardless of whether you choose to allow or not. The Expo push notification tool is also useful for testing push notifications during development.
AppDelegate has a window property that contains all the view controllers that is being displayed. A window is an instance of the UIWindow class and handles the overall presentation of your application’s user interface. Windows work with views (and their owning view controllers) to manage interactions with, and changes to, the visible view hierarchy
SceneDelegate
can handle notification response this way:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
// rootViewController set up code
// say,
// let mainController = ViewController()
// let navigationController = UINavigationController(rootViewController: mainController)
// window.rootViewController = navigationController
// This is UNNotificationResponse
if let notificationResponse = connectionOptions.notificationResponse {
window.makeKeyAndVisible()
// do the pushing on your navigation controller
// navigationController.push()
return
}
window.makeKeyAndVisible()
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With