How to detect iOS version in Objective C?

6.2k Views Asked by At

I'm using Firebase 3.7.x to store my database. Firebase 3.7.x is support iOS 7.0 or higher but my project supports from iOS 6.0. So I want to detect iOS version in device to call @import Firebase. Something like that:

if IOS_7_OR_HIGHER
@import Firebase
else
//do nothing

if IOS_7_OR_HIGHER
- (void)dosomething{}
else
- (void)donothing {}

I know about if #available in swift. Is there any code like if #available in Objective C? Or is there any way to import Firebase for iOS 7 or higher and disable disable for iOS6?

Thanks.

3

There are 3 best solutions below

9
Hemang On

To answer your question you can do it like this:

#ifdef __IPHONE_6_0
    //Do something patchy!
#else
    @import Firebase
#endif 

Humble suggestion: You can consider upgrading your app.

A recent iOS version stats counter from Apple showing that there are only 5% devices which are still having iOS 8, 7 or <= 6. Means, you should drop out support for all those versions or you should start supporting iOS9 onwards.

By doing this you will get all the latest iOS features and you will never have to make this kind of patch in future.

enter image description here

Source: https://developer.apple.com/support/app-store/

0
Shubham bairagi On

You can get device system version by using

-(NSString*)getDeviceVersion{
    return [[UIDevice currentDevice] systemVersion];
}

it will return you device version as string e.g. @"4.0" .

Hope it help you.

0
Pravin S. On

Try below code:

    NSArray *osVersion = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

    if ([[osVersion objectAtIndex:0] intValue] >= 7) {
        // iOS-7 or greater
    } else if ([[osVersion objectAtIndex:0] intValue] == 6) {
        // iOS-6 code
    } else if ([[osVersion objectAtIndex:0] intValue] > 2) {
        // iOS-3,4,5 code
    } else {
        // iOS-1,2... code
    }