I have read UIAlertView/UIAlertController iOS 7 and iOS 8 compatibility thread and tried to implement the following:
if objc_getClass("UIAlertController") != nil {
print("UIAlertController can be instantiated")
//make and use a UIAlertController
}
else {
print("UIAlertController can NOT be instantiated")
//make and use a UIAlertView
}
But in my environment, Xcode 7.1.1 with OS X El Capitan, If I set deployment target to iOS 7.1, Xcode reports error about UIAlertController and fix them by adding availability like follows:
if #available(iOS 8.0, *) {
alertContoller1(alertTitle, alertMessage: alertMessage)
}
and
@available(iOS 8.0, *)
func alertContoller1(alertTitle: String, alertMessage: String) {
let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) {
(action) -> Void in
print("OK button tapped.")
}
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil)
}
Then, when I test my app with iOS simulator 7.1 (Xcode 6.4), my app immediately crash.
Secondly, when I tried to open my project with Xcode 6.4, there are 2 problems.
1.Get compile error with available(iOS 8.0, *)
portion.
2.If I remove available(iOS 8.0, *)
portion, my app crash with error of instantiation of alertController
So, it's a situation of "if I am true to the one, I must be false to the other"
I'd like to confirm that is it really possible to create alert which is compatible with both iOS7.1 and iOS8.0 and after?
Based on my knowings of Android software development, there are annotation @targetAPI and @SuppressWarnings("deprecation"). Are there equivalent function or not?
If Apple's intention is cutting off old things, who rescue the people those who have old devices?