How to make your push notification Open a certain view controller?

后端 未结 4 756
星月不相逢
星月不相逢 2020-12-09 00:43

I looked on SO but I wasn\'t able to find any question that discusses when you receive a push notification how can you then open a specific view controller. For example if y

4条回答
  •  醉话见心
    2020-12-09 01:10

    //This method is called when user tap on the notification
    
          func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    
               print("user clicked on the notification")
               let userInfo = response.notification.request.content.userInfo
    
               print(userInfo)
    
               //check your response and navigate to specific view controller
               moveToNextViewController()
          }
    
         func moveToNextViewController() {
        //Add code for present or push view controller
               let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier:"ViewController") as! ViewController                    
              self.navigationController?.pushViewController(vc, animated: true)
        }
    

提交回复
热议问题