How Programmatically Restart an iPhone App in iOS

Force iphone app to restart programmatically?

First of all, although it is possible to force kill your app, this is not allowed by Apple and will rejected. Even if it wasn't rejected, there is no way to restart your app once it's killed. You just need to find some way to reset your app through your code, as Jason Coco said. It might be more work, but it's worth it to not get rejected by Apple.

Is there any way to restart my iOS app programmatically?

There are no methods available in iOS to restart your application, BUT you could manually reinstantiate initial root UIViewController when needed.


To reinstantiate root UIViewController you could use following static functions in your AppDelegate class:

static func getWindow() -> UIWindow? {
return UIApplication.shared.keyWindow
}

static func resetViewController() {
let window = getWindow()

let controller = ... /// Instantiate your inital `UIViewController`

window?.rootViewController = controller
window?.makeKeyAndVisible()
}

Note:

"Restarting" app is a very uncommon practice and should be avoided in all cases if possible.

How programmatically restart an iPhone app in iOS

The only way I know to do this is not ideal, but it works.

First, your app has to opt out of background execution (multitasking) The app has to quit when exited, not run as a background task. This is done with the plist key UIApplicationExitsOnSuspend.

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

Third, you need a web page hosted somewhere that when loaded will redirect to your app's custom URL scheme.

Forth, the user needs an active Internet connection.

To exit and restart, call UIApplication openURL on your hosted redirecting web page. Your app will exit and safari will launch and load your page. The page will redirect Safari to your custom URL scheme, prompting Safari to internally call openURL, causing iOS to launch your app.

Will I be able to restart my iPhone app programatically to apply language changes in Swift

Swift is a language, not an API. You have the same functionality available to you in Swift as in Objective C, although the syntax and ease of use may differ between the languages.

The answer you linked to therefore already answers the question.


Also, as Hemang points out, don't do this.

It's symptomatic of bad design that you would need to restart the app to change the displayed language.
It would be much better to fix the underlying problem than to apply a hacky band-aid solution such as this.

How to reboot or reload iPhone app programmatically in iOS

Rebooting the app is a bad idea, I'm pretty sure Apple would reject it. However, You could display a popup telling the user to open a close the app to apply your updated information. But the best way would be just to manually call the methods needed to rebuild your app (I.e. the ones that need to use the updated data).
If you have to do some extensive rebuilding (i.e. things that the user would immediately notice) it might be a good idea to add in a "loading" progress bar of sorts.

Can we restart an app programmatically in ios when the phone is turned on

There is a way to do this intended for voip apps by setting your app's UIBackgroundMode to include the voip value. See the Apple Documentation on that for more info, but here is the excerpt about what the voip flag does for you:

The app provides Voice-over-IP services. Apps with this key are
automatically launched after system boot so that the app can
reestablish VoIP services. Apps with this key are also allowed to play
background audio.

If your app is a voip app, then this is what you need. If your app is not a voip app I don't know if this change will make it past Apple's review since that flag is really meant for voip apps.



Related Topics



Leave a reply



Submit