Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created July 22, 2021 20:41
Show Gist options
  • Save SergLam/fdc4876802630cd9a426a1467250eca4 to your computer and use it in GitHub Desktop.
Save SergLam/fdc4876802630cd9a426a1467250eca4 to your computer and use it in GitHub Desktop.
CloseAppElegantly.swift
func quit() {
// home button pressed programmatically - to thorw app to background
DispatchQueue.main.async {
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
// terminaing app in background
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
exit(EXIT_SUCCESS)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment