'UIAlertView' quedó en desuso en iOS 9.0. Utilice UIAlertController con un PreferredStyle de UIAlertControllerStyleAlert en su lugar
He visto más respuestas, pero nada ayudó. Aquí está mi alerta y acción más antiguas para eso
override func viewWillAppear(animated: Bool) {
if Reachability.isConnectedToNetwork() == true {
print("internet connection ok")
} else
{
print("internet not ok")
let alertView: UIAlertView = UIAlertView(title: "Alert ", message: "connect to internet", delegate: self, cancelButtonTitle: "settings", otherButtonTitles: "cancel")
alertView.show()
return
}
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)
{
if buttonIndex == 0 {
//This will open ios devices wifi settings
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root")!)
}
else if buttonIndex == 1
{
//TODO for cancel
exit(0)
}
}
En eso recibo una advertencia:
'UIAlertView' quedó en desuso en iOS 9.0. Utilice UIAlertController con un PreferredStyle de UIAlertControllerStyleAlert en su lugar
Lo intenté :
let alert = UIAlertController(title: "Alert", message: "My Alert for test", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: { (action:UIAlertAction!) in
print("you have pressed the Cancel button")
}))
self.presentViewController(alert, animated: true, completion: nil)
Pero para agregar dos botones y agregar la ruta del índice del botón de método de presionar el enlace de mi código anterior, no puedo hacerlo. No pasa nada para mi botón uialert,
Ayúdame, ¿cómo puedo eliminar esas advertencias y volver a codificar mi Uialert con mi acción de dos botones?
Soy nuevo en Swift. Su ayuda será útil. ¡Gracias!