UIAlertController if iOS 8, otherwise UIAlertView

Rocky Pulley picture Rocky Pulley · Jun 17, 2014 · Viewed 18.6k times · Source

I want to conform to the UIAlertController used in iOS 8 since UIAlertView is now deprecated. Is there a way that I can use this without breaking support for iOS 7? Is there some kind of if condition I can do to check for iOS 8 otherwise do something else for iOS 7 support?

Answer

Erwan picture Erwan · Sep 4, 2014

I think a much better way to check if a class exists (since iOS 4.2) is:

if([ClassToBeChecked class]) {

   // use it

} else {

  // use alternative

}

In your case, that would be:

if ([UIAlertController class]) {
   // use UIAlertController

} else {
  // use UIAlertView

}