如何点击推送通知以在SwiftUI中打开特定屏幕

时间:2020-04-14 16:55:47

标签: swift push-notification swiftui

我正在使用SwiftUI。

我想通过单击推送通知来打开除“根视图”之外的特定屏幕。 有多种使用StoryBoard打开它的方法,但并非没有StoryBoard。

不使用StoryBoard如何实现?

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    var window: UIWindow?

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

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
        // I want to open a screen other than Root View here.
        completionHandler()
    }
    ... }

0 个答案:

没有答案