-8

I have this alert confirm box in swift, it works perfectly in IOS 8, but it does not work in IOS 7, how can i resolve it please ?

Here is my code

 var refreshAlert = UIAlertController(title: "Cerrando la aplicacion!", message: "Seguro que desea Cerrar ?", preferredStyle: UIAlertControllerStyle.Alert)

    refreshAlert.addAction(UIAlertAction(title: "Si", style: .Default, handler: { (action: UIAlertAction!) in
        exit(0)
    }))
    refreshAlert.addAction(UIAlertAction(title: "No", style: .Default, handler: { (action: UIAlertAction!) in
        println("ho hace nada")
    }))
    presentViewController(refreshAlert, animated: true, completion: nil)
  • 6
    Read the docs for UIAlertController. Specifically the "Availability" section. Where it says "Available in iOS 8.0 and later" it means exactly what it says. – Fogmeister May 26 '15 at 14:55
  • 3
    What do you mean not work? `UIAlertController` is introduced in iOS8. For earlier version, as it stated in the doc, use `UIActionSheet` or `UIAlertView`. Note that you can't do an "exit(0)" if you want to be published in AppStore. – Larme May 26 '15 at 14:55
  • I hadn't spotted the `exit(0)`. This is a BIG NO in iOS apps. In fact, it will probably get your app rejected. The user should never exit the app this way. That is what the home button is for. – Fogmeister May 26 '15 at 14:57

1 Answers1

4

From the doc:

Availability Available in iOS 8.0 and later.

A UIAlertController object displays an alert message to the user. This class replaces the UIActionSheet and UIAlertView classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using the presentViewController:animated:completion: method.

So for earlier versions of iOS, use UIActionSheet or UIAlertView (from your example, UIAlertView).

Also, you can't quit the app with an exit(0) if you want to be published in the AppStore, it doesn't respect Apple's Guidelines. More explanation here.

Community
  • 1
  • 1
Larme
  • 24,190
  • 6
  • 51
  • 81