Detect iOS Version for Twitter?

Go To StackoverFlow.com

1

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!

2012-04-04 08:09
by Adam Storr
The only time you should be looking at the iOS Version is for tracking customer usage. Note that this is also considered a personally identifying statistic and shouldn't be examined without a fair request to "Get users' permission to collect data" and from that point you may only send it to yourself for analytics purposes not to a 3rd party. As mentioned in the answer below, query functionality not the OS Version - Lord Andrei 2012-04-04 14:36


6

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.)

2012-04-04 08:21
by Conrad Shultz


1

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
   //tweet
}
2012-04-04 08:17
by jacekmigacz
Note that this is unsatisfactory for a general comparison due to string truncation during float conversion. And in general you shouldn't ever use systemVersion for much of anything anyhow - Conrad Shultz 2012-04-04 08:31
According IEEE 754-1985 standard, positive integral values represented by floating point number less then 7 are guarantied to be lengthened. To prove it, print out a value of FLT_DIG from float.h - jacekmigacz 2012-04-04 08:40
I think we're talking different issues:

NSString *v1 = @"5.1";
NSString *v2 = @"5.1.1";
NSLog(@"%@ is greater than %@: %d", v2, v1, ([v2 floatValue] > [v1 floatValue]));

2012-04-04 01:41:44.795 VersionTest[3624:f803] 5.1.1 is greater than 5.1: - Conrad Shultz 2012-04-04 08:42

(Sorry, comments are quite whitespace unfriendly. - Conrad Shultz 2012-04-04 08:43
Oh. Sure. 5.1.1 will become 5.1. But the question is about Twitter and even truncated and rounded version number is sufficient here - jacekmigacz 2012-04-04 08:47
I realize that, which is what I meant by "general comparison" (in case future readers come across this and thought this would be more broadly applicable). But the bigger point (to me) is that the only reason I can ever think of to use systemVersion is to present a warning about future incompatibilities; current compatibility ought to be established with specific run-time checks - Conrad Shultz 2012-04-04 08:51
Sure. You are right - jacekmigacz 2012-04-04 08:57


1

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.

2012-04-04 16:18
by jonsibley


0

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.

2012-04-04 08:21
by malinois
Not needed in the modern run-time; just weak link the framework. This way you can get compile-time checks for typos, etc., too - Conrad Shultz 2012-04-04 08:22
Ads