XCode base SDK version in code

1.6k Views Asked by At

How can I get the version of the base SDK in code? I am currently building for iOS in XCode 6 and using the base SDK 8.1 . I would like to know if there is any define with the value of the SDK to be able to test it and allow building with different base SDKs.

2

There are 2 best solutions below

0
On BEST ANSWER

This can be done using __IPHONE_OS_VERSION_MAX_ALLOWED (which is the same version as the base SDK version). That can be compared to __IPHONE_8_0 where 8_0 is the iOS release.

For example, at this point you can use the baseSDK 8.0 or 8.1.

3
On

You can find out the version of the current Foundation framework that the code is running against by checking the value of NSFoundationVersionNumber.

If you check out the NSObjCRuntime.h you will find the various version numbers listed in there.

As in regards to building against different versions of the SDK; Apple stops App Store uploads if you don't build against the latest SDK once the cut off date has come into effect - i.e. new apps submitted now must be build against iOS 8 SDK.

What you can however do, is have a lower iOS Deployment Target (this you can find in your project's settings). This will allow for your app to run on older iOS versions, but it will still be built against the latest SDK. Do note though, it is your responsibility to ensure that you do not use any new APIs without first ensuring the current environment supports them e.g. UITextField's selectable property. If you call that whilst running on iOS 6, your app will crash.