当应用程序处于活动状态或后台时,点击通知后,我能够导航到ChatMessageVC,但是当应用程序处于终止状态时,单击通知会将我带到ContactListVC而不是chatMessageVC。任何帮助都是非常可取的。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if let option = launchOptions {
let info = option[UIApplicationLaunchOptionsKey.remoteNotification]
if (info != nil) {
self.application(application, didReceiveRemoteNotification: info as! [AnyHashable : Any])
}
}
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if state == .background {
let navigation = storyboard.instantiateViewController(withIdentifier: "navigationContactPage")
let navigationController = UINavigationController.init(rootViewController: navigation)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
let viewController = storyboard.instantiateViewController(withIdentifier: "chatMessageVC") as! ChatMessagesVC
navigationController.pushViewController(viewController, animated: true)
}
}
答案 0 :(得分:0)
如果您在应用终止时点击通知,则此方法将在您的应用内部调用。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
//Ask your backend developer to send chat id in notification user info. Some how you are succesfully navigating to contacts vc. In the same way open the chatVC using this chat id from contacts vc.
}