swiftxcode9.3

Button that works like home button on iPhone


Is there any way to create a button in Swift that acts in the same way as the iPhone home button? I am looking for a way to do this, whether programmatically or by using Xcode's drag and drop feature for adding buttons.


Solution

  • The next line of code worked for me (Swift 4):

    @IBAction func test(_ sender: UIButton) {
        UIControl().sendAction(#selector(NSXPCConnection.suspend), to: UIApplication.shared, for: nil)
    }
    

    Edit:

    As @martin-r says, I took this code from SO some months ago from here: stackoverflow.com/a/46512619/1187415