IOS Swift- App does not open specific selected tab bar controller index when push notification is received -


my app has 5 tab bar , each time receive push notification app navigate 3rd tab in index. able achieve when app in foreground or background (in active state). if app closed , try open push notification app opens , crashes. below code have

func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject]) {     let tabbar:uitabbarcontroller = self.window?.rootviewcontroller as! uitabbarcontroller     tabbar.selectedindex = 3 } 

kindly let me know doing wrong.

try adding below code in end of difinishlaunchingwithoptions method:

 if let notification = launchoptions?[uiapplicationlaunchoptionsremotenotificationkey] as? [string : anyobject] {             _ = notification["aps"] as! [string : anyobject]              (window?.rootviewcontroller as! uitabbarcontroller).selectedindex = 3         } 

Comments