iOS 7 and iOS 8 living together
This is the first post of 2015. I want to start it with a new category, Tips and Tricks. I’ve found that in my daily work I am fixing many different small pieces of code that, in some cases, will be interesting for you, so I decided to share it in my blog.
The firs one is how to include code that behaves differently when it’s running on iOS 7 than when it’s running on iOS 8, for example. I’ve found two main different ways to do it.
Check the responsiveness to a selector.
Most of the times, the problem comes because of a change in the signature of an API or the deprecation of the methods. In this case the easiest way is to check if the object responds to the given selector. Two examples are NSOperation and UIApplication.
Check the value of NSFundationVersionNumber
The second option is using NSFundationVersionNumber. This option gives you the flexibility to behave differently not because of any restriction, but because functional requirements or just because you like it.
You can use the defined constants:
- NSFoundationVersionNumber_iPhoneOS_2_0
- NSFoundationVersionNumber_iPhoneOS_2_1
- NSFoundationVersionNumber_iPhoneOS_2_2
- NSFoundationVersionNumber_iPhoneOS_3_0
- NSFoundationVersionNumber_iPhoneOS_3_1
- NSFoundationVersionNumber_iPhoneOS_3_2
- NSFoundationVersionNumber_iOS_4_0
- NSFoundationVersionNumber_iOS_4_1
- NSFoundationVersionNumber_iOS_4_2
- NSFoundationVersionNumber_iOS_4_3
- NSFoundationVersionNumber_iOS_5_0
- NSFoundationVersionNumber_iOS_5_1
- NSFoundationVersionNumber_iOS_6_0
- NSFoundationVersionNumber_iOS_6_1
- NSFoundationVersionNumber_iOS_7_0
- NSFoundationVersionNumber_iOS_7_1
Also OS X has its own ones.