Find out the device iOS version at run time

Apple provide a numerous way to get device iOS version at run time :-

1) Using UIDevice Class

float deviceVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

e.g. iOS Version = 6.1

int deviceVersion = [[[UIDevice currentDevice] systemVersion] integerValue];

e.g. iOS Version = 6

2) According to iOS 7 Guideline Document, we can use Foundation Class Predefine Macro to get iOS version :-

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {

// Load resources for iOS 6.1 or earlier

} else {

// Load resources for iOS 7 or later

}

3) We can define Macro in project pch(Pre Compiled Header File) for availability whole project or in certain Class to available in that Class only as follows :-

#define SYSTEM_VERSION_EQUAL_TO(versionStr) ([[[UIDevice currentDevice] systemVersion] compare:versionStr options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(versionStr) ([[[UIDevice currentDevice] systemVersion] compare:versionStr options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(versionStr) ([[[UIDevice currentDevice] systemVersion] compare:versionStr options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(versionStr) ([[[UIDevice currentDevice] systemVersion] compare:versionStr options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(versionStr) ([[[UIDevice currentDevice] systemVersion] compare:versionStr options:NSNumericSearch] != NSOrderedDescending)

We can use above macro as followes to compare iOS version :-

if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {

// code here for less than 5.0 ios version

}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {

// code here for greater than 6.0 ios version

}

630 total views, 1 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Leave a Reply