ios - Initiating all objects in viewController when launched from a push notification -
i have viewcontroller x (not initial view). x childviewcontroller of several parents (several viewcontroller have x child.) on x, there label, table , navigation bar left bar button "pops" parent. when app launched normally, segues, poptoparentviewcontroller, buttons function properly. however, if launch app push notification, x appears navigation bar , button (but not function) , table view.
i don't know why label not showing! , button not go "back". know has "no parent" because i've set "root" in code below.
how can implement want code?
the following in appdelegate.m
- (void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { if ( application.applicationstate == uiapplicationstateinactive || application.applicationstate == uiapplicationstatebackground ) { uistoryboard *mainstoryboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle: nil]; notificationsviewcontroller *viewcontroller= [mainstoryboard instantiateviewcontrollerwithidentifier:@"notificationsviewcontroller"]; uinavigationcontroller *nav = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; [_window setrootviewcontroller:nav]; } }
first of all, application launched - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions method. shall examine launchoptions dictionary check if app opened because of notification. in launch method can access notification object way:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions; { // setup navigation controller here, assume have in code nsdictionary *dictionary = [launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey]; if (dictionary != nil) { nslog(@"%@: did launch notification: %@", [self class], dictionary); // put navigation controllers on nav controller stack david described } [[self window] setrootviewcontroller:navigationcontroller]; [self.window makekeyandvisible]; return yes; } the method - (void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo called only if app had been launched. called when app switching background foreground or when runs. method never called when application starts new process.
Comments
Post a Comment