ios - Redirect a View with Push Notification in AppDelegate -


my aim writing code when user gets push notification, want user redirected view. if user comes push notification , if has been first viewed controller (welcome home screen etc. (but not logged in))

var rootviewcontroller = self.window!.rootviewcontroller as! viewcontroller rootviewcontroller.performseguewithidentifier("hospitalsegue", sender: self) 

this couple lines of code working, however, if user has been in view controller (sign in/login/user page etc.) piece of code doesn't work , redirect. tried , still cannot come solution. final goal this:

if let rootviewcontroller = self.window!.rootviewcontroller as? viewcontroller {     var rootview: userviewcontroller = userviewcontroller()      if let window = self.window{         window.rootviewcontroller = rootview     }      rootviewcontroller.performseguewithidentifier("hospitalsegue", sender: self)     println(self.window?.rootviewcontroller) } 

can give me idea?

the answer code objective-c, want talk logic. this, when creating push notification, must set userinfo value pass data push notification.

use delegate method : application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult))completionhandler

you can decide if view want show handling userinfo

nsdictionary *seguedictionary = [userinfo valueforkey:@"aps"];  nsstring *seguename=[[nsstring alloc]initwithformat:@"%@",[seguedictionary valueforkey:@"seguename"]];  if([seguename isequaltostring:@"hospitalsegue"])  { // implement code redirect } 

Comments