Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check iOS version at runtime?

This is sort of a follow on from my last question. I am using beginAnimations:context: to setup an animation block to animate some UITextLabels. However I noticed in the docs that is says: "Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods instead."

My question is I would love to use animateWithDuration:animations: (available in iOS 4.0 and later) but do not want to exclude folks using iOS 3.0. Is there a way to check to iOS version of a device at runtime so that I can make a decision as to which statement to use?

like image 513
fuzzygoat Avatar asked Oct 05 '10 10:10

fuzzygoat


People also ask

How do I find my OS version in Objective C?

In Objective-C, you need to check the system version and perform a comparison. [[NSProcessInfo processInfo] operatingSystemVersion] in iOS 8 and above.

How do I find my swift version OS?

If you're using Swift 2 and you want to check the OS version to use a certain API, you can use new availability feature: if #available(iOS 8, *) { //iOS 8+ code here. }


2 Answers

Simpler solution for anyone who'll need help in the future:

NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];  if ( 5 == [[versionCompatibility objectAtIndex:0] intValue] ) { /// iOS5 is installed      // Put iOS-5 code here  } else { /// iOS4 is installed      // Put iOS-4 code here           } 
like image 170
ArtSabintsev Avatar answered Sep 22 '22 04:09

ArtSabintsev


In many cases you do not need to check iOS version directly, instead of that you can check whether particular method is present in runtime or not.

In your case you can do the following:

if ([[UIView class] respondsToSelector:@selector(animateWithDuration:animations:)]){ // animate using blocks } else { // animate the "old way" } 
like image 34
Vladimir Avatar answered Sep 23 '22 04:09

Vladimir