【问题标题】:How to redirect to detail view of cell in List when tapped on that notification using SwiftUI?使用SwiftUI点击该通知时如何重定向到列表中单元格的详细视图?
【发布时间】:2020-04-17 13:25:37
【问题描述】:

我在内容视图中有列表,并且列表通过导航链接连接到详细视图。 我在 SwiftUI 中使用用户通知 我想在点击通知时自动重定向到详细视图

来自应用代理:

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

        let application = UIApplication.shared

        // Show on Tap
        application.applicationIconBadgeNumber = 0

        if application.applicationState == .inactive {

            let detailView = DetailView(item: DummyData[1])

            if let window = UIApplication.shared.keyWindow {
                self.window = window
            }

            self.window?.rootViewController = UIHostingController(rootView: detailView)
            self.window?.makeKeyAndVisible()
        }

        completionHandler()
    }

此代码显示详细视图,但无法在应用中导航(导航视图)。

如何使用 SwiftUI 在点击 WhatsApp、Instagram 等通知时重定向到详细视图?

【问题讨论】:

    标签: ios swift notifications swiftui usernotifications


    【解决方案1】:

    您需要有一些标签/数据,以便导航到其详细视图。然后您可以在您的NavigationView 中使用NavigationLink(_,destination:,tag:,selection:),其中selection 绑定到该标签。

    详细解释和示例代码见https://nalexn.github.io/swiftui-deep-linking/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-23
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多