I'm basically receiving a remote notification and I want to redirect my user to the correct VC as soon as he clicks the notification.
I'm doing it using NSNotificationCenter to perform a segue from my rootVC, leading the user to the correct VC.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "chooseCorrectVC:", name:chatNotificationKey, object: nil)
Since the observer was previously loaded, my chooseCorrectVC function is called first, so this is my "Init/Deinit" Log. I consider Init whenever viewDidLoad() is called.
rootVC INIT
SecondVC DEINIT
rootVC DEINIT
func chooseCorrectVC(notification:NSNotification){
self.performSegueWithIdentifier("chatSegue", sender: notification)
NSNotificationCenter.defaultCenter().removeObserver(self)
}
The issue is: the VC that is called with chatSegue does not get initialized and goes straight to deinit. I'm not sure why it's happening, maybe I'm not removing the observer correctly.
Any suggestions?
If you are receiving the remote notification, I suggest you to just handle the notification at AppDelegate.swift at method:
You can manage another view controller to be push on viewdidload of homeviewcontroller via setting flag here. On view did load