Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the current iPhone OS version at runtime and compare version strings?

Tags:

iphone

How can you determine and compare (>, <, etc.) the current OS version of the iPhone that the app is running on? There is a certain bug in 3.0 but not in 3.1+ so I'd like to be able to skip out a bit of code if the current OS version is not >= 3.1.

This needs to be at runtime not compile time!

like image 983
Michael Waterfall Avatar asked Dec 27 '09 00:12

Michael Waterfall


2 Answers

You can for instance do something like this:

NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
 {
    //Do some clever stuff
 }
like image 72
Mez Avatar answered Sep 19 '22 14:09

Mez


Do you mean determine the version of the OS? The SDK is fixed at build time, but the OS may change. To get the OS version, use [UIDevice currentDevice]. systemVersion. To get the SDK version, I think you can use __IPHONE_OS_VERSION_MIN_REQUIRED.

like image 22
Ben Gottlieb Avatar answered Sep 18 '22 14:09

Ben Gottlieb