У меня есть больше ответов, но ничего не помогло. Вот мой старый сигнал и действие для этого
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)
}
}
В том, что я получаю предупреждение:
'UIAlertView' устарел в iOS 9.0. Используйте UIAlertController с preferredStyle UIAlertControllerStyleAlert вместо
Я пробовал:
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)
Но для добавления двух кнопок и добавления указательного пути метода нажатия кнопки свяжите мой старый код, я не могу этого сделать. Ничего не происходит из-за моей кнопки uialert,
Пожалуйста, помогите мне, как я могу удалить эти предупреждения и перекодировать мой Uialert с помощью двух действий кнопки.
Я новичок в swift. Ваша помощь будет полезна. Спасибо!