Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Created May 11, 2018 21:50
Show Gist options
  • Save Tulakshana/2ee6444fdec33f95a52abd2d348f1c7b to your computer and use it in GitHub Desktop.
Save Tulakshana/2ee6444fdec33f95a52abd2d348f1c7b to your computer and use it in GitHub Desktop.
Experimental code to exit an iOS app.
@IBAction func btnExit0Tapped (sender: UIButton) {
exit(0) // Not recommended by Apple https://developer.apple.com/library/content/qa/qa1561/_index.html and app crashes
}
@IBAction func btnSuspendTapped (sender: UIButton) {
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil) // App exits gracefully
}
@IBAction func btnFatalErrorTapped (sender: UIButton) {
fatalError() // App will crash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment