tags:

views:

294

answers:

2

Based on this it looks like it's hard to get OS version detection absolutely correct. However, I'm looking for something half-decent which warns users of OS X Tiger and below about possible compat issues with my product.

The heuristic I can think of is first detecting whether the OS is a Mac (relatively simple) and then matching the user agent with the regex 10[/._][0-4] to detect Tiger and below. I don't really care about cases where the user agent is modified - I want a fair strike rate detecting OS X versions, not a 100% solution.

Any other suggestions/recommendations?

Also, bonus points for pointing to a tool that helps me test this by generating known user agent strings for different OS version + browser version combinations.

Thanks!

A: 

Any other suggestions or recommendations?

Yes, don't do it. Not perhaps what you want to hear but you're right, it's unreliable at best.

Being inherently lazy, I'd opt for the solution that involved the least amount of work. That's a big red text area next to the download link, stating something like:

Beware. This product is only supported with OS X 10.5 or later. Please do not attempt to use with earlier versions.

Then let the user decide.

If you want to protect them further, make your executable program check itself once it's running on their box. I gather OS X has uname on it, or a similar tool which can reliably get the OS version. If it doesn't meet the specs at that point, you can simply exit with a similar message:

I warned you. But no, you wouldn't listen. Had to go and download me anyway, didn't you. Well, now I'm not going to run at all, and you've wasted all that precious bandwidth. Silly, silly man, now go away.

Of course, your error message may be more tactful than mine :-)

paxdiablo
Onfortunately, my app won't even load pre-Leopard so showing the error on first run involves the much more painful path of bootstrapping my app in a 10.4 compatible launcher. Blech!And I trust flaky detection over user intelligence. A lot of people running OS X have no idea what version they're running. Bold red text warning them to not use this with versions older than 'Foo' will only intimidate them, I believe.
psychotik
+1  A: 

Humm, I believe that using the get_browser() function with an up to date php_browscap.ini is the wisest choice in this case, not 100% sure if it'll tell you the OS version though.

EDIT: The browscap.ini file also provides you with enough user agent strings, if you still decide to do all the parsing work by yourself.

EDIT: Seems that there is also a PHP implementation that doesn't require you to alter the php.ini file.

EDIT: Based on the user agent string you provided me here is the code that I believe works best:

if (preg_match('~Mac OS X (.*?);~', $_SERVER['HTTP_USER_AGENT'], $matches) > 0)
{
    $version = preg_replace('~[^0-9]+~', '.', trim($matches[1]));

    if (version_compare($version, '10.5', '>=') === true)
    {
     // ok
    }

    else
    {
     // not ok
    }
}

else
{
    // not Mac OS X
}
Alix Axel
That would work well for Windows client version - not as much for Mac OS versions unless I do something similar to what I've written above anyways. Thanks though - I didn't know about this very nifty PHP feature.
psychotik
Indeed, however I think that if you use the version_compare() function together with the version index returned by get_browser() you'll less likely make mistakes compared to using just a regex approach.
Alix Axel