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?
Asked
Active
Viewed 5,341 times
3 Answers
8
Set the app's info.plist key: UIApplicationExitsOnSuspend to True.

hotpaw2
- 70,107
- 14
- 90
- 153
-
I like your answer, but I think the asker wants the application to remain in multitasking but just begin from the root view controller.... – Sid Nov 30 '11 at 18:14
-
hotpaw2 is correct. that's what i was looking for. however, i selected "Application does not run in background" and set it to YES. – sexitrainer Dec 01 '11 at 15:08
-
Deprecated on iOS 13.0 – Unreality Sep 16 '19 at 09:50
1
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);
}

Alex Coplan
- 13,211
- 19
- 77
- 138
1
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.
}
}

Louie
- 5,920
- 5
- 31
- 45
-
You can also use app delegate methods as Alex pointed out, but don't try to exit. You should change what information the user is presented with it. Both app delegate and notifications work equally well. – TigerCoding Nov 30 '11 at 17:20