I have an issue with a simple alert view that used to work but since it has changed in iOS 8, Xcode tells me I have to have a "if available version check" but the more I do what it tells me the more errors I get. What is the correct way of having a UIAlertView
that works with different iOS versions with a simple title, message and Ok button? This is the code I have been using which used to work fine:
let Alert = UIAlertController(title: "This is the title", message: "This is the message", preferredStyle: .Alert)
let DismissButton = UIAlertAction(title: "OK", style: .Cancel, handler: {
(alert: UIAlertAction) -> Void in
})
Alert.addAction(DismissButton)
self.presentViewController(Alert, animated: true, completion: nil)
EDIT: With the research/suggestions of Xcode I have come up with the following code. The error messages I am now getting are " use of unresolved identifier 'alert' " on the last two lines.
if activePlace == -1 {
if #available(iOS 8.0, *) {
let Alert = UIAlertController(title: "No place Selected", message: "Please press on back button and select a place in the list to use directions", preferredStyle: .Alert)
} else {
// Fallback on earlier versions
}
if #available(iOS 8.0, *) {
let DismissButton = UIAlertAction(title: "OK", style: .Cancel, handler: {
(alert: UIAlertAction) -> Void in
})
} else {
// Fallback on earlier versions
}
Alert.addAction(DismissButton)
self.presentViewController(Alert, animated: true, completion: nil)