I have an app which can only run from iPhone 4s and up, I need to be able to distinguish on the client side (i.e. javascript) the device, and load the app or redirect accordingly. Is there any way to detect it? thanks
Asked
Active
Viewed 1,120 times
0
-
is my answer a good starting point for you to solve this checking? reply if you need more information or questions! – nzs Jun 06 '13 at 13:09
-
thanks, it was useful in helping me realize there's no way to distinguish between 4 and 4s on client side and find my solution elsewhere. – Ohad Milchgrub Jun 06 '13 at 20:22
1 Answers
1
I see these three options for you:
1) use a precooked open source script to check this and based on the result you do a redirect. You can use this for example: http://detectmobilebrowsers.com/
2) you implement a javascript which do a checking based on the navigator parameters. See this and a quote code from that SO answer.
function iOSversion() { if (/iP(hone|od|ad)/.test(navigator.platform)) { var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; } }
3.) you can use rewrite rules at Apache side to redirect to the proper page based on user-agent. See this.
For all 3 options you have a problem that it is hardly possible to distinguish between iPhone 4 and 4s. See this SO answer.
To mention only if you have to check retina capability you can use this JS too:
var isRetina = window.matchMedia("(-webkit-min-device-pixel-ratio: 2)").matches;
More info what is min-device-pixel-ratio here: link. Also info on media queries here: link