Keep getting this error:
'UIAlertView' was deprecated in iOS 9.0: UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
Can someone help me edit this code?
if #available(iOS 8.0, *) {
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: alertOKTitle, style:.destructive, handler: { alertAction in
self.okButtonPressed()
alert.dismiss(animated: true, completion: nil)
}))
alert.addAction(UIAlertAction(title: alertCancelTitle, style:.cancel, handler:{ alertAction in
self.cancelButtonPressed()
alert.dismiss(animated: true, completion: nil)
}))
alert.addAction(UIAlertAction(title: alertRemindLaterTitle, style:.default, handler: { alertAction in
self.remindLaterButtonPressed()
alert.dismiss(animated: true, completion: nil)
}))
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let controller = appDelegate.window?.rootViewController
controller?.present(alert, animated: true, completion: nil)
} else {
let alert = UIAlertView()
alert.title = alertTitle
alert.message = alertMessage
alert.addButton(withTitle: alertCancelTitle)
alert.addButton(withTitle: alertRemindLaterTitle)
alert.addButton(withTitle: alertOKTitle)
alert.delegate = self
alert.show()
}
}
internal func alertView(_ alertView: UIAlertView , clickedButtonAt buttonIndex: Int){
if(buttonIndex == 0)
{
cancelButtonPressed()
}
else if(buttonIndex == 1)
{
remindLaterButtonPressed()
}
else if(buttonIndex == 2)
{
okButtonPressed()
}
alertView.dismiss(withClickedButtonIndex: buttonIndex, animated: true)
}