ios - Implement didReceiveRemoteNotification to show a new viewController when push comes -
ios - Implement didReceiveRemoteNotification to show a new viewController when push comes -
i have application should loads viewcontroller when remote force notification comes, have code in appdelegate.m:
- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo { nslog(@"remote notification %@", userinfo); if( [[mtmapiclient sharedclient] isloggedin: nil]){ if (userinfo && userinfo[@"aps"] && userinfo[@"aps"][@"extra"]) { if ( application.applicationstate == uiapplicationstateactive ) { [self playsound]; } } [notificationhelper pushnotificationcame:userinfo view:self.tabbarcontroller.selectedviewcontroller]; } } my application tabbed application (like appstore , itunes) maintain reference uitabbarcontroller in appdelegate.
my notification helper code is:
+ (void) pushnotificationcame:(nsdictionary*)userinfo view:(uinavigationcontroller*) viewcontroller { nsstring* otp; if (userinfo && userinfo[@"aps"] && userinfo[@"aps"][@"extra"]) { otp = (nsstring*)userinfo[@"aps"][@"extra"][@"otp"]; [authorization loadauthbyotp:otp success:^(authorization *auth) { dispatch_async(dispatch_get_main_queue(), ^{ uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mystoryboard" bundle:[nsbundle mainbundle]]; transactiondetailviewcontroller* apptransactiondetailsview = [storyboard instantiateviewcontrollerwithidentifier:@"transactiondetails"]; apptransactiondetailsview.authorization = auth; [viewcontroller pushviewcontroller:apptransactiondetailsview animated:yes]; }); } failure:^(nsstring *error, errortype errortype) { nslog(@"pushnotificationcame loadauthbyotp failed error: %@", error); }]; } } this works in 70% of scenarios, when sign out of application , sign in, when force notification comes self.tabbarcontroller.selectedviewcontroller , "viewcontroller" in pushnotificationcame method not active view in tab bar pushviewcontroller doesn't work.
in other words there 3 tabs in application tab a, b, c when force notification comes i'm on tab self.tabbarcontroller.selectedviewcontroller in debugger b viewcontroller when force new viewcontroller goes tab b , nil happens. no error no new viewcontroller well. happens when sign out , sing in application, works!
my sign out code:
[viewcontroller.navigationcontroller.tabbarcontroller performseguewithidentifier:@"logoutsegue" sender:viewcontroller]; and sign in code:
[self performseguewithidentifier:@"fromsignintoapplications" sender:self]; which takes user first tab in tabbarcontroller.
and in appdelegate
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.tabbarcontroller = (uitabbarcontroller *)self.window.rootviewcontroller; }
it looks problem building stack of view controllers when logout / login @ root of stack have original tab view controller , have logout, login, new tab view controller. @ point in time app delegate still has reference original tab view controller , nil works more.
(note, may not have logout view controller, principle applies login view controller)
what should consider doing presenting logout , login view controllers rather pushing them, then, when login complete, rather pushing fromsignintoapplications dismiss , reveal original tab view controller again. uses less memory , result in less future issues observation , like.
the alternate post login notification after segue app delegate can new tab view controller - but, isn't window root view controller need create changes or think how work.
ios objective-c iphone
Comments
Post a Comment