当应用程序关闭时(不在后台或非事件状态)推送通知时,我不想打开特殊的 ViewController 当应用程序在后台运行时,但当应用程序关闭时,Xcode 推送到 Main ViewController
我尝试使用所有应用程序状态,但不起作用
if(application.applicationState == .background) {
let dict = userInfo["aps"] as? NSDictionary
if let cont = dict {
let cate = cont["category"] as? String
if let category = cate {
switch category {
case "NEWS":
let storyboard = UIStoryboard(name: "Shops", bundle: nil)
let NewBoard = storyboard.instantiateViewController(withIdentifier: "MainShopsViewController")
let tabbar = self.window?.rootViewController as? UITabBarController
let navcontrol = tabbar?.selectedViewController as? UINavigationController
tabbar?.selectedIndex = 1
navcontrol?.pushViewController(NewBoard, animated: true)
self.window?.makeKeyAndVisible()
default:
break
}
}
}
}
最佳答案
你可以使用这个函数来做到这一点..
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// tell the app that we have finished processing the user’s action / response
completionHandler()
}
关于ios - 当应用程序关闭时从推送通知打开特定的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56869498/