0

I have an alert window in my code with two buttons 'Ok' and 'Exit'. I want quit simulator when 'Exit' is pressed.

func alertWindow() {
    let alert = UIAlertController(title: "Alert", message: "Isn't type of gesture", preferredStyle: UIAlertController.Style.alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: { (action: UIAlertAction!) in
        // Quite simulator here
    }))

    self.present(alert, animated: true, completion: nil)

}
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

2

This is not possible and there is no need to do it, except while you test your app. You should write a testing script that will be executed when you test your app. Then you should add something like this in your script:

sudo killall "iOS Simulator"

After that, you can call the script within the code with something like this Answer (Check 1st & 2nd answers)

Emm
  • 1,963
  • 2
  • 20
  • 51
0

There is NO legit way of doing it in iOS like Android. The only way you can do what you want is to force a crash on pressing the Exit button.

For example, declare an optional variable with nil value and unwrap it, although it is not recommended to exit your app this way.

badhanganesh
  • 3,427
  • 3
  • 18
  • 39