svarrall
svarrall

Reputation: 9287

Detecting iOS devices that browse to rails site through an App (ie. Twitter)

I'm using this piece of code that is working correctly to detect iOS devices when browsing through the Safari browser:

def mobile_user_agent?
@mobile_user_agent ||= ( request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"]   [/(Mobile\/.+Safari)/] )
end

But it doesn't detect a user coming to the site through an App's browser on the device. Mainly Twitter.

I believe this is the UA for a twitter user, so how do you accomodate for this (and other Apps as well?)

"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405"

Upvotes: 0

Views: 2734

Answers (1)

Pavel S
Pavel S

Reputation: 1543

What i would do is change the regex to something like

/(Mobile\/.+Safari)|(AppleWebKit\/.+Mobile)/

Upvotes: 1

Related Questions