How to programmatically restart an iPhone application in iOS

How to programmatically restart an iPhone application in iOS?

I find this way http://writeitstudios.com/david/?p=54

But maybe something simple.

+4
source share
4 answers

The only way I know this is not perfect, but it works.

Firstly, your application should refuse to perform the background (multitasking). When you exit the application, the application should exit, and not perform a background task. This is done using the plist key UIApplicationExitsOnSuspend.

Secondly, your application needs to register a custom URL scheme that can be used to launch the application.

-, -, -, URL-.

Forth, .

, UIApplication openURL - . , . Safari URL-, Safari openURL, iOS .

+20

, , Cocoa, iOS. iOS ( Apple ), exit(0);, . iPhone.

+1

, Apple . .

0

AppDelegate

(void)applicationDidBecomeActive:(UIApplication *)application
{
}

Here you can put the logic to find out if the application should restart or continue to do what it did. For example, you may first have a BOOLvariable appMustRestartthat false, but works as true when something happens in your application, that you want a fresh restart next time.

if (appMustRestart)
{
    [self resetVars];  // call a method that resets all your vars to initial settings

    // INSERT CODE HERE TO TRANSFER FOCUS TO INITIAL VIEWCONTROLLER
}
-1
source

All Articles