Уведомление Pu sh не перенаправляется при нажатии - PullRequest
1 голос
/ 03 марта 2020

Я реализовал код перенаправления в appdelegate, пока мы нажимаем на уведомление pu sh. Приложение открывается на своей домашней странице и не перенаправляет на конкретную страницу.

Проблема, обнаруженная во время отладки

Когда приложение находится на переднем или заднем плане, уведомление перенаправляется на определенную страницу. но когда приложение закрывается из фона, уведомление не перенаправляется на конкретную страницу, отображается только домашняя страница.

Кто-нибудь может предложить хорошее решение для этого? Следующий код используется для перенаправления.

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()
    }
}
...