6

Possible Duplicate:
How can we programmatically detect which iOS version is device running on?

How do I check if a device is running iOS 6? I need to check to see if the os is iOS 6 in order to change my youtube video urls because of the release notes from Apple on how to handle them in iOS6

As of iOS 6, embedded YouTube URLs in the form of http://www.youtube.com/watch?v=oHg5SJYRHA0 will no longer work. These URLs are for viewing the video on the YouTube site, not for embedding in web pages. Instead, the format that should be used is described in https://developers.google.com/youtube/player_parameters.

I was thinking of an if else statement to handle this.

thanks for any help

Community
  • 1
  • 1
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • 1
    Let me refer you to [this question and answer](http://stackoverflow.com/questions/7848766/how-can-we-programmatically-detect-which-ios-version-is-device-running-on)... – James Oct 12 '12 at 10:11
  • Check this: http://stackoverflow.com/questions/3339722/check-iphone-ios-version – Resh32 Oct 12 '12 at 10:11
  • take the macro defined here. http://stackoverflow.com/a/8042056/593336 – mayuur Oct 12 '12 at 10:16
  • @mayuur macro only work on compile time, meaning that if you compile with iOS 6 it will use the iOS 6 way. But running the same app on iOS 5 it will still be using the iOS 6 way. Run time checking would be better. – rckoenes Oct 12 '12 at 10:19
  • @hanumanDev what actually you want to do...!!!! – Kamar Shad Oct 12 '12 at 10:23
  • @rckoenes Is it so? I didn't know that. But that problem wouldn't come up if I run it after a complete cleanup and reset the simulator right? – mayuur Oct 12 '12 at 10:26
  • @mayuur yes, a marco is compile time. Thus recompiling it with an other SDK wil work. – rckoenes Oct 12 '12 at 10:28

3 Answers3

35

As Before comparing float parameters you should put 6.0 in a float variable so that LHS and RHS should be the same to compare:

float currentVersion = 6.0;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion)
{
    NSLog(@"Running in IOS-6");
}
Bhupendra
  • 2,525
  • 18
  • 20
  • 1
    [[UIDevice currentDevice] systemVersion] is probably the most inefficient way of checking for iOS version numbers. Its not clear why, but this function takes precious CPU cycles to return a version number. Use NSFoundationVersionNumber instead. https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/miscellaneous/Foundation_Constants/Reference/reference.html – Abhinit Jan 18 '14 at 14:11
1
NSString *versionString = [[UIDevice currentDevice] systemVersion]; // iOS version as string
int versionStringInt = [ver intValue]; // iOS version as int
float versionStringFloat = [ver floatValue]; // iOS version as float
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
0

Try below

 float deviceVersion   = [[[UIDevice currentDevice] systemVersion] floatValue];
 NSLog(@"My Device version is :%f ",deviceVersion);

I hope it'll help you.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
  • You might want to do something like `if (deviceVersion >= 6.0)` because as soon as 6.1 rolls out , that code will fail and assume its on 5.x again. – Shayne Oct 12 '12 at 10:39
  • Checking for an explicit version number is almost always wrong. Check for capabilities instead. – Roger Oct 12 '12 at 10:48
  • hey @Shayne you are right but here i just show that i am also not favor for above that's why ik am modifying my answer. – Kamar Shad Oct 12 '12 at 10:55
  • @Roger So how *do* you check for capabilities instead? For example Using the new `UIActivityViewController` in IOS6 for social sharing functions, and calling `TWTweetComposeViewController` and email sharing manually when its not supported ? – Yarek T Dec 30 '12 at 21:42