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 Firebaseelse//do nothingif IOS_7_OR_HIGHER- (void)dosomething{}else- (void)donothing {}I know aboutif #available in swift. Is there any code likeif #available in Objective C? Or is there any way to import Firebase for iOS 7 or higher and disable disable for iOS6?
Thanks.
- 1Possible duplicate ofHow to check iOS version?Arya McCarthy– Arya McCarthy2017-05-15 03:36:34 +00:00CommentedMay 15, 2017 at 3:36
- @aryamccarthy: What is duplicate? I asked for iOS 6, not iOS 8.TienLe– TienLe2017-05-15 03:39:04 +00:00CommentedMay 15, 2017 at 3:39
- Possible duplicate ofHow can we programmatically detect which iOS version is device running on?l'L'l– l'L'l2017-05-15 03:39:20 +00:00CommentedMay 15, 2017 at 3:39
- The information is easily generalized. If you don't like the accepted answer, read the other answers.Arya McCarthy– Arya McCarthy2017-05-15 03:40:43 +00:00CommentedMay 15, 2017 at 3:40
- @TienLe Any specific reason, why you're supporting iOS 6? FYI, Less than 1% of devices are on iOS 6.Imad Ali– Imad Ali2017-05-15 03:43:09 +00:00CommentedMay 15, 2017 at 3:43
3 Answers3
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.
Comments
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 }Comments
To answer your question you can do it like this:
#ifdef __IPHONE_6_0 //Do something patchy!#else @import Firebase#endifHumble 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.
9 Comments
Explore related questions
See similar questions with these tags.


