I have code like this. if I receive a pushnotification and I tap on it I want to redirect to specific viewcontroller but I want to pass a value (hidden inside notification) to a specific view controller
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive, response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let application = UIApplication.shared
if(application.applicationState == .inactive)
{
LocalData.indexTabBar = nil
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if LocalData.emailLogin != nil && LocalData.passwordLogin != nil && LocalData.tokenLogin != nil {
let initialViewController = storyboard.instantiateViewController(withIdentifier: "MainControllerIfSavedLogin") as! UITabBarController
initialViewController.selectedIndex = 2 //Selecting tab here
self.window?.rootViewController = initialViewController
} else{
let initialViewController = storyboard.instantiateViewController(withIdentifier: "loginViewController") as UIViewController
self.window?.rootViewController = initialViewController
}
self.window?.makeKeyAndVisible()
}
completionHandler()
}
Get it with
let userInfo = response.notification.request.content.userInfo
Then send it
let tab = ------ as! MainControllerIfSavedLogin
let vc = tab.viewControllers!.first as! LoginViewController
vc.info = userInfo
class LoginViewController : UIViewController {
var info:[String:Any]?
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.