5

For instance, let's say my iOS-application supports down to iOS 7.0, and I want to make an alert. In iOS 7, I would use UIAlertView. In iOS 8/9, this has been deprecated by UIAlertController. Do I have to check if currentVersion > iOS7, and then create BOTH alerts, an alertView for iOS7 and an alertController for iOS8+? Or is it okay to use UIAlertView in an iOS7-app, even though it will be running on iOS9+ devices eventually?

Will I ever need to check what the current iOS-version is, and implement multiple objects (one for each version), in simple matters like this?

Sti
  • 8,275
  • 9
  • 62
  • 124

1 Answers1

1

Deprecation is just a note that a feature may be removed in a future version. The deprecated class or method still works, though.

So you can simply continue using UIAlertView and face the risk of breaking in a future iOS version. It still does work on iOS 9. There's no guarantee that it will continue to work on iOS 10, though.

The best solution here is to check whether UIAlertController is available at runtime. If it is, use that class for your alert, otherwise fall back to UIAlertView.

You usually do not check the iOS version! It's better to check whether a method or class is available, except in the very rare cases were Apple explicitly tells you check the iOS version: this happens when a method that was considered to be private was made public by Apple.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Quite often deprecated features will "work" but they will have issues – Bradley Thomas Mar 15 '16 at 13:39
  • @BradThomas: What kind of issues do you mean? In the case of `UIAlertView`, that thing always had issues which is why it's succeeded by `UIAlertController`. Other than that, I'm not aware of any deprecated class or method which has changed its behavior (until it was removed, of course). – DarkDust Mar 15 '16 at 13:51
  • In our project, upgrading to iOS8 caused flaky behavior with UIAlertView. Questions such as http://stackoverflow.com/questions/26228729/ios-8-uialertview-uialertcontroller-not-showing-text-or-buttons – Bradley Thomas Mar 15 '16 at 13:56
  • 1
    @BradThomas: Thanks for sharing! That's really the first time I've heard about issues with deprecated classes/methods. – DarkDust Mar 15 '16 at 14:00
  • @DarkDust But since my project supports iOS 7 I'm not actually receiving the deprecation. I only see the deprecation when creating a new project, only supporting down to iOS 8 or 9. Does this mean I *could* be using a lot of deprecated code (that has been deprecated after iOS7), without knowing it? Is there a quick way to analyze the code in my project for objects and methods that are deprecated in newer iOS-version (I.E to show deprecation warnings that isn't deprecated in iOS 7, but might cause problems for iOS8, 9, 10 etc.). – Sti Mar 15 '16 at 14:09
  • @Sti: I'm not aware of a way to do such a check. You do not get a deprecation warning as you're still targeting a version (deployment target) where the class/method is not yet deprecated (and there won't be a replacement in that version). – DarkDust Mar 15 '16 at 14:33