0

所以由于某种原因,从AppDelegate. 我有一个通知,UNNotificationAction我处理方法中的动作选择didReceiveResponse()

这是功能:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
  
       // Print message ID.
       if let messageID = userInfo[gcmMessageIDKey] {
         print("Message ID: \(messageID)")
       }
    
   
    if response.actionIdentifier == "viewNewEvent" {
        let dashVC: UIViewController = storyboard.instantiateViewController(withIdentifier: Constants.StoryboardIDs.StudentEventDashboardStoryboardID) as! StudentSegmentedTableViewController
        let navDashVC = UINavigationController(rootViewController: dashVC)
        self.window?.rootViewController = navDashVC
        self.window?.makeKeyAndVisible()
        
    }

       print(userInfo)
    print("didReceiveResponse called")

    completionHandler()
}

if当我在通知中选择操作时,语句中的代码块永远不会运行。起初,我强制展开所有内容,但我收到一条错误消息,提示 viewController 为 nil,现在当我运行并选择通知中的操作时,什么也没有发生。

viewController 怎么可能是 nil 呢?我遇到了类似的事情,并决定尝试一下SceneDelegate,它确实有效,但是有很多错误需要我最终修复。在这种情况下使用UISceneand是否比尝试实例化正确的 VC 更好?或者有解决办法吗?UIWindowSceneUIWindow

4

1 回答 1

0

好的,经过几个小时的研究,我意识到这不能再完成了,AppDelegate我现在必须使用 SceneDelegate 来处理任何事情UIWindowUIScene.

于 2021-03-07T01:58:36.240 回答