Reputation: 8563
Is there a way of knowing if I am running in iOS 5 (or less) or 6 (or later)?
I am using Google API for directions in iOS 5 and I would like to use Apple's in iOS 6.
Upvotes: 0
Views: 573
Reputation: 4221
This answers your question. Check iPhone iOS Version https://stackoverflow.com/a/5337804/1368748
Upvotes: 2
Reputation: 150565
Since you are programming against iOS 5 you can use the more recent method of checking for weakly linked libraries by just calling the class's class
method, which returns nil if it's not supported.
As an example (taken from the documentation):
if ([UIPrintInteractionController class]) {
// Create an instance of the class and use it.
}
else {
// The print interaction controller is not available.
}
This requires LLVM and Clang, but as your supporting iOS5 and iOS6, you should be using this anyway.
Upvotes: 1
Reputation: 21902
Look for a specific class that was introduced in the new OS instead of trying to ask the OS itself for a version.
For example:
if (NSClassFromString(@"UICollectionView")) {
// It's iOS 6
}
Upvotes: 1
Reputation: 19867
You can get the iOS version from:
[[UIDevice currentDevice] systemVersion]
In general, its a better practice to test if the feature you need is available or not, rather than relying on specific iOS versions. As @mprivat mentions, NSClassFromString
is one method for accomplishing this.
Upvotes: 1