Created
May 28, 2017 23:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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