我正在使用本地通知,並試圖呈現特定的viewController
,但我嘗試了在此論壇中找到的內容,並且看到顯示的視圖出現異常行爲在 this picture here: 而這裏的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()
方法)? 任何幫助將不勝感激。
它目前的作品? – Mannopson
看看源代碼上面的圖片,視圖控制器是空白的,它不應該是。 –