Reputation: 1450
Apparently, my use of Twitter oAuth (token request) doesn't work in iOS 5... how can I keep this code for anything below iOS 5 and use the new Twitter Framework for iOS 5+?
Is it possible to detect iOS versions?
Thanks!
Upvotes: 2
Views: 680
Reputation: 8050
First and foremost, the other answers are correct-- you should avoid using iOS version number to check if features exist.
HOWEVER: In case you do indeed have a good reason to check iOS version, my all-time favorite answer for checking iOS version number is in this StackOverflow answer. So elegant.
Upvotes: 1
Reputation: 6734
Detect if the Twitter class is in the installed os :
if (NSClassFromString(@"TWTweetComposeViewController")) {
//use Twitter Framework
}
Do not forget to make the Twitter Framework optional in the list of Frameworks.
Upvotes: 0
Reputation: 8808
You (almost) never want to query iOS (or even framework) versions. That (usually) means you're solving the wrong problem.
In this case, you really want to know "can I use Twitter.framework?"
Thanks to the magic of weak linking, you can try something like:
if ([TWTweetComposeViewController canSendTweet]) {
// Do something
}
else {
// Use your original code
}
You can also check for lower level framework components, e.g.:
if ([TWRequest class]) {
// Do something
}
else {
// Use your original code
}
(Obviously you will need to link against Twitter.framework and include the requisite headers.)
Upvotes: 6
Reputation: 789
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
//tweet
}
Upvotes: 1