简体   繁体   中英

go to home screen of the iphone app after coming from background

I am trying to find out how should i take the user to the home screen of my app, after he comes back from the background.

I don't want to take the user to the home screen all the time when he is coming from the background.

But only when he clicks "view" on my push notification alert and the app was in the background at that time, i want to take him to the home screen.

But if he is opening the app from the background in general he should go where ever he was left off last time he clicked on the home button and went to background

Any help is appreciated.

Thanks, Yogesh

There one bool property in info.plist--Application does not run in background

you should change that according to your requirement.

Ok i am not sure if this right way of doing it or not, but this is what i did, as my application have a tabbarcontroller the first thing that i did is i implemented the delegate method of the tabbarcontroller "didSelectViewController"

// By doing this every time you select a tab it will come back to the rootViewController of that tab

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

     if ([viewController isKindOfClass:[UINavigationController class]]){
         [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
     }

}

and then on didReceiveRemoteNotification

if(tabBarController.selectedIndex == 1){
    UINavigationController *navigationController  = (UINavigationController*)tabBarController.selectedViewController;
    [navigationController popToRootViewControllerAnimated:NO];
    [[[navigationController viewControllers ] objectAtIndex:0]viewWillAppear:YES];
}else{
    self.tabBarController.selectedIndex = 1;
}

so let me explain what this is doing, it is checking if the current tab is 1 if it is then it will remove all the view from the navigation stack to bring the view to the root view, if the current tab is not 1 and just make it to 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM