Skip to content

Instantly share code, notes, and snippets.

@AppleBetas
Created May 28, 2017 23:32
Show Gist options
  • Save AppleBetas/c46e92bcc4cb50e0241202b7459b6fee to your computer and use it in GitHub Desktop.
Save AppleBetas/c46e92bcc4cb50e0241202b7459b6fee to your computer and use it in GitHub Desktop.
UIApplication+GracefulExit.swift - exit an app (using private APIs) with the default iOS animation
//
// UIApplication+GracefulExit.swift
//
// Created by AppleBetas on 2017-05-28.
//
import UIKit
extension UIApplication {
/// Exit the application to the home screen and then terminate it.
func performGracefulExit() {
let suspendSelector = Selector("suspend") // swift can't hide warnings ffs
if self.responds(to: suspendSelector) {
Timer.scheduledTimer(withTimeInterval: 1, repeats: false, block: { _ in
exit(0)
})
self.perform(suspendSelector)
} else {
exit(0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment