How to find out all iPad versions from user-agent string?

I wanted to find out the entire version of the iPad (excluding iPhone, iPod) from the user agent string, currently during testing I got the following line

Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3 

Question: Will the following code work fine for all iPads?

 String userAgentStr = request.getHeader("User-agent"); if (userAgentStr.contains("iPad")) { //do my logic } 

EDIT:

I use the Dolphin browser from the iPad, but I get the following UA line:

 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en_US) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C148 Safari/6533.18.5 

Similarly, iBrowser from the iPad UA line:

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

So my above code breaks ...

+4
source share
1 answer

I highly recommend using feature detection instead of device discovery, as suggested in the comments. One library commonly used to detect a function will be modernizr .

If you need to use device discovery, this meaning basically means that your code should work.

+1
source

All Articles