通过场景委托从选项卡栏控制器中双加载视图控制器

时间:2020-10-14 21:23:20

标签: swift uiscenedelegate

我将UNUserNotificationCenterDelegate设置为Scene Delegate的扩展。目标是在应用程序中打开特定标签(无论是通过打开应用程序,将应用程序置于前台还是在前台切换标签)。

当前,应用程序和选项卡按预期打开,但是最终两次加载了选项卡的视图控制器。起初,我以为该错误与该应用程序已经打开或在后台运行有关,但我尝试将其关闭并做了同样的事情。

我现在认为这与我一直无法弄清楚如何在场景委托中切换选项卡有关。

如果它正在加载从SECOND通知中获取的信息,那将是可行的,但是它首先加载了该信息,然后第二次擦除了它。

对此有任何想法或可能对此有其他解决方案吗?

extension SceneDelegate: UNUserNotificationCenterDelegate { 
  func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void) {
        
    defer { completionHandler() }
    
    let identity = response.notification.request.content.categoryIdentifier
    guard identity == categoryButtonsId,
    let action = ActionButtonsId(rawValue: response.actionIdentifier)
    else { return }
    let payload = response.notification.request.content

    switch action {
    case .accept:
        let tabController = createTabBar()
        tabController.selectedIndex = 0
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        self.window!.rootViewController!.present(tabController, animated: false)
        break
    case .reject:
        break 
    }
  }
}

0 个答案:

没有答案
相关问题