Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Runtime iOS Version Checking
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
/*
* Usage
*/
if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
...
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
...
}
@Jusung
Copy link

Jusung commented Dec 9, 2013

Simple, Easy and Awesome!

@ramadana
Copy link

ramadana commented Jun 12, 2014

it really useful ! thanks alex

@lzubiaur
Copy link

lzubiaur commented Oct 14, 2014

Simple and useful. Thanks!

@gino24
Copy link

gino24 commented Nov 16, 2014

Thanks, so simple and useful !

@TommyQu
Copy link

TommyQu commented May 12, 2015

Could you tell me where is Version.m file?

@jsras
Copy link

jsras commented Oct 27, 2015

nice one - thanks!

@ramezanpour
Copy link

ramezanpour commented Oct 29, 2015

Thanks! Very useful.

@haxpor
Copy link

haxpor commented Nov 2, 2015

Thanks man. Works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment