ios - Swift navigate to View from notification -


i making ios application. have made notification when near places. , works fine. want navigate view when press notification. thinking when sms. press notification sms , navigate me correct sms conversation.

when application receives push notification, method in uiapplicationdelegate called. notification needs handled differently depending on state app in when it’s received:

if app wasn’t running , user launches tapping push notification, push notification passed app in launchoptions of

 application(_:didfinishlaunchingwithoptions:) 

if app running , in foreground, push notification not shown function call immediately

 application(_:didreceiveremotenotification:) 

if app running or suspended in background , user brings foreground tapping push notification, function called.

application(_:didreceiveremotenotification:)  

so can change root view controller on these functions :-

    if let notification = launchoptions?[uiapplicationlaunchoptionsremotenotificationkey] as? [string: anyobject] {        //change root view controller      } 

this checks whether value uiapplicationlaunchoptionsremotenotificationkey exists in launchoptions. if does, push notification payload sent.


Comments