Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if device is running iOS 5 or higher [duplicate]

Tags:

xcode

ios

ios5

Possible Duplicate:
Check iPhone iOS Version

One of the changes made in iOS 5 is the ability to override the drawrect methods. This means I need to change the appearance of the navigationBar and tabBar on a different way. I am able to use apple new methods:

[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navigationBarBackgroundRetro.png"] forBarMetrics:UIBarMetricsDefault];

//I create my TabBar controlelr
tabBarController = [[UITabBarController alloc] init];

// I create the array that will contain all the view controlers
[[UITabBar appearance] setBackgroundImage:
    [UIImage imageNamed:@"navigationBarBackgroundRetroTab.png"]];

[[UITabBar appearance] setSelectionIndicatorImage:
    [UIImage imageNamed:@"tab_select_indicator"]];

I'm developing an app for iOS 4.3 and 5.0. However, iOS 5 ignores the drawrect method that I'm overriding, so it should run the above code. How can I check the iOS version so I can use the above code if the device is on iOS 5?

like image 250
Alex van Rijs Avatar asked Oct 20 '11 11:10

Alex van Rijs


People also ask

How do I know if I have the latest iOS version?

Go to Settings > General > Software Update. The screen shows the currently installed version of iOS and whether an update is available.

How do I know if my phone is linked to another device iPhone?

From the Devices section of your Apple ID account page, you can see all of the devices that you're currently signed in to with your Apple ID, including Android devices, consoles, and smart TVs: Sign in to appleid.apple.com,* then select Devices.

How can I know my iPhone IMEI number is original?

Check the IMEI number of the phone on the product's box. Now visit Apple's website https://checkcoverage.apple.com/in/en . Click on the option 'IMEI number' here and type in the number printed on the phone box. If you don't find any details there, then the phone is fake.


1 Answers

The samples below work for any version number. e.g.: to detect iOS 5 instead 7, replace 7 with a 5 in the code.

AvailabilityInternal.h macros

This detects the SDK you are building with:

#ifdef __IPHONE_7_0
  // iOS 7.0
#endif

This detects the version set as Deployment Target in the General tab of your target configuration:

  #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 
    // iOS 7.0 or later
  #else 
    // less than 7
  #endif

NSFoundation version

BOOL isAtLeastIOS61 = NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_6_1;
BOOL isAtMost61 = NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1;
BOOL is7x = floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1;

If you ⌘ click NSFoundationVersionNumber, you'll see version constants for iOS and OSX. The constant for the current SDK is always missing.

Core Foundation version

BOOL atLeastIOS61 = kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_6_1;

As with NSFoundationVersionNumber, the SDK version is missing.

Device system version

NSString *version = [[UIDevice currentDevice] systemVersion];

BOOL isAtLeast6 = [version floatValue] >= 6.0;
BOOL isAtLeast7 = [version floatValue] >= 7.0;

An alternative way:

BOOL isAtLeast6 = [version hasPrefix:@"6."];
BOOL isAtLeast7 = [version hasPrefix:@"7."];

An alternative way:

BOOL isAtLeast6 = [version compare:@"6.0" options:NSNumericSearch] != NSOrderedAscending
BOOL isAtLeast7 = [version compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending

In case of concerns about float/string conversion, let it be know that everything above reports correctly if the version is equal or greater, for any possible iOS version (6.0, 6.0.1, 6.1, etc.).

like image 143
15 revs Avatar answered Sep 24 '22 01:09

15 revs