Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to exit an iOS app without it looking like a crash? - Swift
func showMessageResetApp(){
let exitAppAlert = UIAlertController(title: "Restart is needed",
message: "We need to restart the app on your first login to the app.\n Please reopen the app after this.",
preferredStyle: .alert)
let resetApp = UIAlertAction(title: "Close Now", style: .destructive) {
(alert) -> Void in
// home button pressed programmatically - to thorw app to background
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
// terminaing app in background
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
let laterAction = UIAlertAction(title: "Later", style: .cancel) {
(alert) -> Void in
self.dismiss(animated: true, completion: nil)
present(exitAppAlert, animated: true, completion: nil)
Copy link

shayneoneill commented Jun 18, 2019

I should note, apple will probably reject the app still. exiting the app (and presumably resetting) is straight up not allowed in the app store rules.

Copy link

zunjae commented Jul 9, 2019

Don't use this.

Copy link

cpellet commented Jun 10, 2020

This is bad practice and will definitely be rejected by Apple!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment