我正在使用Swift编写应用程序,我需要显示alert .应用程序必须与iOS 7和iOS 8兼容.既然UIAlertView
已被UIAlertController
取代,我如何在不判断系统版本的情况下判断UIAlertController
是否可用?我一直听说苹果建议我们不要为了确定API的可用性而判断设备的系统版本.
这是我在iOS 8上使用的,但在iOS 7上,它会以"dyld: Symbol not found: _OBJC_CLASS_$_UIAlertAction
"崩溃:
let alert = UIAlertController(title: "Error", message: message, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alert.addAction(cancelAction)
presentViewController(alert, animated: true, completion: nil)
如果我在iOS 8上使用UIAlertView,我会收到以下警告:Warning: Attempt to dismiss from view controller <_UIAlertShimPresentingViewController: 0x7bf72d60> while a presentation or dismiss is in progress!