Anyway, the code you posted looks fine to me:
Latest Safari UA:
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25
Latest Chrome UA:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17
Bearing in mind the above-mentioned caveats, this should work as expected.
BTW, I don't know if you already found it, but when doing this kind of thing, this site can be quite helpful.