【发布时间】:2017-02-09 14:35:48
【问题描述】:
我正在处理本地通知,我正在尝试提供一个特定的 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() 方法)?
任何帮助将不胜感激。
【问题讨论】:
-
目前有效吗?
-
看源代码上面的图片,视图控制器不应该是空白的。
标签: swift viewcontroller appdelegate unusernotificationcenter usernotifications