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

发布于 2024-11-14 00:41:30 字数 215 浏览 4 评论 0原文

我试图找出用户从后台返回后如何将其带到我的应用程序的主屏幕。

当用户来自后台时,我不想一直将用户带到主屏幕。

但只有当他点击我的推送通知警报上的“查看”并且应用程序当时在后台时,我才想把他带到主屏幕。

但是,如果他一般从后台打开应用程序,他应该转到上次单击主页按钮并转到后台时离开的地方,

如有任何帮助,我们将不胜感激。

谢谢, 约格什

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-11-21 00:41:30

info.plist 中有一个 bool 属性——应用程序不在后台运行,

您应该根据您的要求更改它。

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

you should change that according to your requirement.

嘿咻 2024-11-21 00:41:30

好吧,我不确定这种做法是否正确,但这就是我所做的,因为我的应用程序有一个 tabbarcontroller,我做的第一件事是我实现了 tabbarcontroller“didSelectViewController”的委托方法

// 通过这样做每次你选择一个选项卡时,它都会返回到该选项卡的 rootViewController

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

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

}

,然后在 didReceiveRemoteNotification 上

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

,让我解释一下它在做什么,它会检查当前选项卡是否为 1,如果是,那么它将删除其中的所有视图导航堆栈将视图带到根视图,如果当前选项卡不是 1,则将其设置为 1。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文