How to check whether the platform running a browser or webview is an iPad
The Problem
When you want to know whether the platform running a webview or web browser is an iPad, you usually use the code below. GPT also suggests this.
const isIpad = navigator.maxTouchPoints > 1 && /MacIntel/.test(navigator.platform);
However, the code above does not work in the Chrome browser. That is because navigator.platform in the Chrome browser is iPad.
On top of that, navigator.platform is a deprecated API.
The Solution
You can create a function like the one below to check whether the device is an iPad. With this approach, it works fine in the Chrome browser as well.
const isIPadOS = () => {
const haveTouchPoint =
navigator.maxTouchPoints && navigator.maxTouchPoints > 1;
const isiPadUserAgent =
/Macintosh/i.test(navigator.userAgent) || /iPad/i.test(navigator.userAgent);
return haveTouchPoint && isiPadUserAgent;
};
20250206
Leave a comment