Restart iphone application from the very beginning

风流意气都作罢 提交于 2020-01-02 11:07:09

问题


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?


回答1:


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




回答2:


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.
    }
}



回答3:


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:

- (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);
}


来源:https://stackoverflow.com/questions/8329999/restart-iphone-application-from-the-very-beginning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!