我正在使用本地通知,我正在尝试提供一个特定的通知,viewController
但我已经尝试了我在这个论坛中找到的内容,我得到了一个不寻常的行为,
这里的图片显示了这个视图:这是AppDelegate
的源代码.swift:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("didReceive Method called")
if response.actionIdentifier == "actionOne" {
DispatchQueue.main.async(execute: {
self.notificationAction1()
})
} else if response.actionIdentifier == "actionTwo" {
DispatchQueue.main.async(execute: {
self.notificationAction2()
})
} else if response.actionIdentifier == "actionThree" {
}
completionHandler()
}
func notificationAction1() {
redirectToVC()
}
func redirectToVC() {
let toVC = VersesViewController()
if self.window != nil && self.window?.rootViewController != nil {
let rootVC = self.window?.rootViewController!
if rootVC is UINavigationController {
(rootVC as! UINavigationController).pushViewController(toVC, animated: true)
} else {
rootVC?.present(toVC, animated: true, completion: {
//Do something
})
}
}
}
代码有什么问题(尤其是redirectToVC()
方法)?任何帮助将不胜感激。