Sti
Sti

Reputation: 8493

Do I have to handle deprecation when I'm supporting a lower iOS-version?

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?

Upvotes: 5

Views: 118

Answers (1)

DarkDust
DarkDust

Reputation: 92384

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.

Upvotes: 1

Related Questions