Swift 点击时推送通知未重定向
在点击推送通知时,我在appdelegate中实现了重定向代码。应用程序正在打开其主页,而不是重定向到特定页面 调试期间发现的问题 当应用程序位于前台或后台时,通知会重定向到特定页面,但当应用程序从后台终止时,通知不会重定向到特定页面,而只显示主页 有人能提出一个好的解决方案吗?以下代码用于重定向Swift 点击时推送通知未重定向,swift,xcode,apple-push-notifications,Swift,Xcode,Apple Push Notifications,在点击推送通知时,我在appdelegate中实现了重定向代码。应用程序正在打开其主页,而不是重定向到特定页面 调试期间发现的问题 当应用程序位于前台或后台时,通知会重定向到特定页面,但当应用程序从后台终止时,通知不会重定向到特定页面,而只显示主页 有人能提出一个好的解决方案吗?以下代码用于重定向 func directions(activity: String,info:[String:Any], currentView:UIViewController){ if let _
func directions(activity: String,info:[String:Any], currentView:UIViewController){
if let _ = UserDefaults.standard.value(forKey: "user_id"){
let storyboard = UIStoryboard.init(name: "Home", bundle: nil)
let homeView = storyboard.instantiateViewController(withIdentifier: "HOMEViewController") as! HOMEViewController
if #available(iOS 13.0, *) {
UIApplication.shared.statusBarStyle = .lightContent
self.navigatinController = UINavigationController(rootViewController: homeView)
self.navigatinController.isNavigationBarHidden = true
self.window!.rootViewController = self.navigatinController
self.window!.makeKeyAndVisible()
}else{
self.window?.rootViewController = homeView
}
switch activity {
case "CHAT_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Chat", bundle: nil)
let chat = storyboard.instantiateViewController(withIdentifier: "ChatHomeViewController_new") as! ChatHomeViewController_new
chat.segmentTag = 0
chat.isFromPush = true
chat.pushId = info["user_id"] as! String
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(chat, animated: false)
}else{
self.window?.rootViewController?.present(chat, animated: false, completion: nil)
}
case "GROUP_CHAT_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Chat", bundle: nil)
let chat = storyboard.instantiateViewController(withIdentifier: "ChatHomeViewController_new") as! ChatHomeViewController_new
chat.segmentTag = 1
chat.isFromPush = true
chat.pushId = info["group_id"] as! String
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(chat, animated: false)
}else{
self.window?.rootViewController?.present(chat, animated: false, completion: nil)
}
case "JOURNAL_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let journalView = storyboard.instantiateViewController(withIdentifier: "JournalViewController") as! JournalViewController
journalView.url = info["id"] as! String
journalView.isFromPush = true
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(journalView, animated: false)
}else{
self.window?.rootViewController?.present(journalView, animated: false, completion: nil)
}
case "NEWS_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let newsPage = storyboard.instantiateViewController(withIdentifier: "NewPageViewController") as! NewPageViewController
newsPage.isFromPush = true
newsPage.pushDate = info["id"] as! String
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(newsPage, animated: false)
}else{
self.window?.rootViewController?.present(newsPage, animated: false, completion: nil)
}
case "FORUM_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let forum = storyboard.instantiateViewController(withIdentifier: "ForumViewController") as! ForumViewController
forum.isFromPush = true
forum.isFromPushId = info["id"] as! String
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(forum, animated: false)
}else{
self.window?.rootViewController?.present(forum, animated: false, completion: nil)
}
case "EVENT_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let eventsView = storyboard.instantiateViewController(withIdentifier: "EventViewController") as! EventViewController
eventsView.isFromPush = true
eventsView.pusteventId = info["id"] as! String
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(eventsView, animated: false)
}else{
self.window?.rootViewController?.present(eventsView, animated: false, completion: nil)
}
case "KNOWLEDGE_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let knowledge = storyboard.instantiateViewController(withIdentifier: "KnowledgeCenterViewController") as! KnowledgeCenterViewController
knowledge.titleValue = "Knowledge Center"
knowledge.id = info["id"] as! String
knowledge.isFromPush = true
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(knowledge, animated: false)
}else{
self.window?.rootViewController?.present(knowledge, animated: false, completion: nil)
}
case "LEGAL_ACTIVITY":
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let knowledge = storyboard.instantiateViewController(withIdentifier: "KnowledgeCenterViewController") as! KnowledgeCenterViewController
knowledge.titleValue = "Legal Updates"
knowledge.id = info["id"] as! String
knowledge.isFromPush = true
if #available(iOS 13.0, *){
(self.window?.rootViewController as! UINavigationController).pushViewController(knowledge, animated: false)
}else{
self.window?.rootViewController?.present(knowledge, animated: false, completion: nil)
}
default:
showHomeView()
}
}else{
showLoginScreen()
}
}
您知道
Deeplink
体系结构吗?您可以阅读此内容以更好地理解->始终提供与您的问题相关的实际代码是否可以使用Deeplink重定向推送通知?答案是:可以,您可以使用Deeplink执行。这是因为您的初始VC尚未加载。如果收到推送通知,请加载VC。您可以通过布尔标志来完成。您知道Deeplink
体系结构吗?您可以阅读此内容以更好地理解->始终提供与您的问题相关的实际代码是否可以使用Deeplink重定向推送通知?答案是:可以,您可以使用Deeplink执行。这是因为您的初始VC尚未加载。如果收到推送通知,请加载VC。您可以通过布尔标志来完成。