0

My app's deployment target is 7.0 . I want to use both UIAlertController and UIAlertView. I read somewhere that checking for iOS versions is not good, so i used this code :

if (NSClassFromString("UIAlertController") != nil) {
// UIAlertController
} else {    
// UIAlertView

But even if do that, i still get that "correctable" error "UIAlertController is only available on iOS 8.0 or newer" and i have to choose between 3 'Fix-it' options :

  • Add 'if #available' version check ( if #available(iOS 8.0, *) { ... } else { ... })
  • Add @available attribute to enclosing instance method
  • Add @available attribute to enclosing class

What should i do ? Currently using Xcode 7 GM

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SergeH
  • 608
  • 1
  • 5
  • 20
  • 1
    `if #available` is the best option if you want to support both iOS versions at the same time. – David Skrundz Sep 17 '15 at 16:41
  • If you are getting messages about `UIAlertView` being deprecated then your deployment target is not iOS 7. Check the deployment target for both the project and your target. – rmaddy Sep 17 '15 at 17:07
  • @rmaddy no " UIAlertView deprecated " errors, my target deployment is already set to 7.0 – SergeH Sep 17 '15 at 17:45

1 Answers1

0

As stated, the best way to do this is using the #available function. I've attached a code example for you.

if #available(iOS 8.0, *) {

    } else {

    }

#available is the best way to do these checks.

stktrc
  • 1,599
  • 18
  • 30