1

我想检测客户端正在使用什么操作系统。我可以检测它是移动设备还是桌面设备。如何检测它使用的是IOS还是Android?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.52 Chrome/28.0.1500.52 Safari/537.36

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko)

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
4

1 回答 1

3

使用“浏览器”之类的宝石或类似的宝石。

https://github.com/fnando/browser

browser = Browser.new(:ua => "some string", :accept_language => "en-us")
browser.name        # readable browser name
browser.version
browser.safari?
browser.opera?
browser.chrome?
browser.mobile?
browser.tablet?
browser.firefox?
browser.ie?
browser.ie6?        # this goes up to 10
browser.modern?     # Webkit, Firefox 17+, IE 9+ and Opera 12+
browser.platform    # return :mac, :windows, :linux or :other
browser.mac?
browser.windows?
browser.linux?
browser.blackberry?
browser.meta        # an array with several attributes
browser.to_s        # the meta info joined by space
于 2013-09-20T03:09:57.950 回答