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.
Asked
Active
Viewed 428 times
0
-
4Don’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 Answers
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
-
This looks like a copy from https://stackoverflow.com/a/46512619/1187415, without attribution. – Martin R Jun 18 '18 at 07:17
-