0

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.

sanjaykmwt
  • 586
  • 3
  • 19
G Kofman
  • 13
  • 4
  • 4
    Don’t do this. The phone already has a home button. It doesn’t need another one. You really really shouldn’t be quitting the app yourself. Even from a button press. Let Apple deal with the running and quitting/suspending of your app. – Fogmeister Jun 18 '18 at 07:24

1 Answers1

1

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

thxou
  • 691
  • 7
  • 20