ローカルの通知で作業していますが、特定の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
ソースコードの上にある画像を見ると、ビューコントローラは空白になっています。 –