简体   繁体   English

go 从后台进入 iphone 应用程序的主屏幕

[英]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但是,如果他通常从后台打开应用程序,他应该 go 上次他点击主页按钮并进入后台时离开的地方

Any help is appreciated.任何帮助表示赞赏。

Thanks, Yogesh谢谢, 尤格什

There one bool property in info.plist--Application does not run in background info.plist 中有一个 bool 属性——应用程序不在后台运行

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"好的,我不确定这种做法是否正确,但这就是我所做的,因为我的应用程序有一个 tabbarcontroller 我做的第一件事是我实现了 tabbarcontroller“didSelectViewController”的委托方法

// By doing this every time you select a tab it will come back to the rootViewController of that tab // 通过这样做,每次你 select 一个选项卡它会回到那个选项卡的 rootViewController

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

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

}

and then on didReceiveRemoteNotification然后在 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.所以让我解释一下这是在做什么,它正在检查当前选项卡是否为 1,如果当前选项卡不是 1,那么它将从导航堆栈中删除所有视图以将视图带到根视图,如果当前选项卡不是 1 并且只是使其变为 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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