我有出租车管理应用程序,其中从 UIViewcontroller 扩展了一个名为 corecontroller 的类以使用所有常用功能。在这里,我们添加了通知观察器和卸妆器
override func viewDidAppear(_ animated: Bool) {
//registering gcm reciever
super.viewDidAppear(animated)
NotificationCenter.default.addObserver(self,
selector: #selector(showReceivedGCMMessageCore(_:)),
name: NSNotification.Name(rawValue: appDelegate.messageKey), object: nil)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: appDelegate.messageKey), object: nil)
}
在 MyViewController
中class MyViewController: Corecontroller{
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
}
}
当FCM到达时,它将取消 corecontroller 内部的功能,因为功能之一是从扩展的corecontroller中打开一个页面,说 AcceptReqeustViewcontroller ,在此当用户接受请求时,AcceptReqeustViewcontroller 需要撤回给ViewController,所以我做到了
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let rootController = kStoryBoard.main.instantiateViewController(withIdentifier:kViewControllers.mainPage) as! MainViewController
appDelegate.window?.rootViewController = rootController
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
将新的viewcontroller初始化为rootviewcontroller并关闭,但是在这种情况下,要执行的 MyViewController viewDidAppear()
函数只是想知道为什么会这样?