I\'m wondering if it\'s possible to detect whether a browser is running on iOS, similar to how you can feature detect with Modernizr (although this is obviously device detec
It's probably worth answering that iPads running iOS 13 will have navigator.platform
set to MacIntel
, which means you'll need to find another way to detect iPadOS devices.
The user-agents on iOS devices say iPhone or iPad in them. I just filter based on those keywords.
Slightly update the first answer using a more functional approach.
const isIOS = [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod',
].indexOf(navigator.platform) !== -1;
This sets the variable _iOSDevice
to true or false
_iOSDevice = !!navigator.platform.match(/iPhone|iPod|iPad/);
You can also use includes
const isApple = ['iPhone', 'iPad', 'iPod', 'iPad Simulator', 'iPhone Simulator', 'iPod Simulator',].includes(navigator.platform)
In my case the user agent was not good enought since in the Ipad the user agent was the same as in Mac OS, therefore I had to do a nasty trick:
var mql = window.matchMedia("(orientation: landscape)");
/**
* If we are in landscape but the height is bigger than width
*/
if(mql.matches && window.screen.height > window.screen.width) {
// IOS
} else {
// Mac OS
}