xcode 从一开始就重启iphone应用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8329999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:37:13  来源:igfitidea点击:

Restart iphone application from the very beginning

iphonexcodeuiviewcontroller

提问by sexitrainer

when i close my application (via HOME button) and open it up again, how do i force the application to restart from the very beginning view and not from the last location that was shown (before it was closed)? is it a setting in the project?

当我关闭我的应用程序(通过 HOME 按钮)并再次打开它时,我如何强制应用程序从最开始的视图而不是从显示的最后一个位置(关闭之前)重新启动?它是项目中的设置吗?

回答by hotpaw2

Set the app's info.plist key: UIApplicationExitsOnSuspend to True.

将应用程序的 info.plist 键:UIApplicationExitsOnSuspend 设置为 True。

回答by Alex Coplan

This is caused by multi-tasking, i.e. the app isn't properly quitting.

这是由多任务处理引起的,即应用程序没有正确退出。

To ensure that it pops back, try this in the applicationWillEnterForeground, like so:

为确保它弹出,请在 中尝试此操作applicationWillEnterForeground,如下所示:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

Or a very quick and dirty way, is to actually quit the application when it enters the background (note this probably isn't the best way).

或者一种非常快速和肮脏的方法,是在应用程序进入后台时实际退出应用程序(注意这可能不是最好的方法)。

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[NSThread mainThread] exit];
    // OR
    exit(0);
}

回答by Louie

Look for a notification from the phone letting you know that the phone "Became Active" which will only happen if the app was running, then sent to background, then pulled up again. Once you know it has become active again you can push your Home view.

寻找来自手机的通知,让您知道手机“变得活跃”,这只会在应用程序运行时发生,然后发送到后台,然后再次拉起。一旦您知道它再次变为活动状态,您就可以推送您的主页视图。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    if (application.applicationState == UIApplicationStateInactive ) {
         //application has been sent to the background
    }

    if(application.applicationState == UIApplicationStateActive ) { 
        //The application has become active an alert view or do something appropriate.
        //push home view here.
    }
}