0

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.

TienLe
  • 614
  • 2
  • 9
  • 33
  • 1
    Possible duplicate of [How to check iOS version?](http://stackoverflow.com/questions/3339722/how-to-check-ios-version) – Arya McCarthy May 15 '17 at 03:36
  • @aryamccarthy: What is duplicate? I asked for iOS 6, not iOS 8. – TienLe May 15 '17 at 03:39
  • Possible duplicate of [How can we programmatically detect which iOS version is device running on?](http://stackoverflow.com/questions/7848766/how-can-we-programmatically-detect-which-ios-version-is-device-running-on) – l'L'l May 15 '17 at 03:39
  • The information is easily generalized. If you don't like the accepted answer, read the other answers. – Arya McCarthy May 15 '17 at 03:40
  • @TienLe Any specific reason, why you're supporting iOS 6? FYI, Less than 1% of devices are on iOS 6. – Imad Ali May 15 '17 at 03:43
  • @Imad: For my app, It is not 1%, It is 10%. And I have about 4M users. So, I need to support them. – TienLe May 15 '17 at 03:49
  • What you're trying to do is use compile time conditionals to do something that needs to be done at runtime. See the linked problems to resolve your issue. – ThomasW May 15 '17 at 03:49

3 Answers3

2

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.

Shubham bairagi
  • 943
  • 7
  • 25
0

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
    }
Pravin S.
  • 465
  • 7
  • 22
-2

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/

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • You could also potentially alienate loyal users who may have been using your product on older versions of iOS too and can't run a newer version. Sometimes it's better to leave some options open... – l'L'l May 15 '17 at 03:42
  • 1
    Hi. Thanks for your comment. I knew about that. 1. Your comment is not answer for my question. 2. I have 10% users that use iOS 6. My total user are about 4M. And 10% of 4M is a big number. – TienLe May 15 '17 at 03:46
  • @I'L'l I can support you if he's asking for iOS 7 at least, he's asking for iOS 6 and it's too old now. Even Apple is saying to upgrade your app to the latest iOS versions. At least, he can think to upgrade to iOS 7. What's wrong to get update your app to provide great features rather than not upgrading and making use of un-updated things? – Hemang May 15 '17 at 03:47
  • 1
    @TienLe, Ok, thanks for sharing more information about your app user base. Those people may use iPhone 4/4s at least, they can surely upgrade to iOS 7. As you're having these much of users – it's likely that your app is outstanding. So if they want to use your app, they should consider to upgrade their phone to a new age. – Hemang May 15 '17 at 03:49
  • @Hemang: Have you ever seen an older iPhone or iPad Mini with minimum specs running the latest iOS? For older devices It's best not to upgrade, as the device becomes so sluggish it's essentially useless; and not everyone can go out and buy a new one every year. – l'L'l May 15 '17 at 03:52
  • @Hemang: Yes. I see. But I can not say with users that: "Hey. I will not support you anymore". I need step by step to do that. I need to limit some function and coerce them upgrade the OS version. -_- – TienLe May 15 '17 at 03:53
  • I have updated my answer to help the question. However, I am still keeping my original answer to let future readers might understand the possible potential to get updated to the latest iOS. I am not suggesting for rest 21%. I am only saying to drop for those 0.% (which are < iOS 7). It's rarely too late if you are still not upgrading yourself for only one reason that you can't afford a new phone or your phone will be slow? By doing this, you are missing so many good apps, animations, security things and much more. ** It's always good to be updated. ** – Hemang May 15 '17 at 04:11
  • Also, as per my knowledge, if you will upgrade your iOS to the version which Apple is supporting to upgrade your iDevice should not slug or hangs often as Apple Devs have created it especially to work under such hardware available. So likely it's good to upgrade the iDevice if there's an update available. Which opens so many good things for your iPhone. – Hemang May 15 '17 at 04:14
  • **People can now remove their downvote as I am giving two answers for a single question.** One which OP requires and another one which helps future readers to understand what to choose? – Hemang May 15 '17 at 04:16