I would like to know if is any method to restart my app programmatically. It's an iOS app and I work with Xcode 12.3 in swift.
I would like to know if is any method to restart my app programmatically. It's an iOS app and I work with Xcode 12.3 in swift.
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.