sexitrainer
sexitrainer

Reputation: 1367

Restart iphone application from the very beginning

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?

Upvotes: 2

Views: 5356

Answers (3)

hotpaw2
hotpaw2

Reputation: 70673

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

Upvotes: 8

Alex Coplan
Alex Coplan

Reputation: 13361

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

Upvotes: 1

Louie
Louie

Reputation: 5940

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

Upvotes: 1

Related Questions