In iOS 13 apple changed the user-agent that iPad uses.
Instead of (for example)
Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10
it become (for example)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15
My question is how can we distinguish between iPad and mac now?
The major difference between the macOS and iOS is the interface and the framework. The macOS is a computer-based and mouse-keyboard operating system, whereas the iOS is a touch screen interfacing operating system. The application framework in iOS is the UIKit, and the macOS uses the AppKit.
iPadOS is a mobile operating system developed by Apple Inc. for its iPad line of tablet computers. It is a rebranded variant of iOS, the operating system used by Apple's iPhones, renamed to reflect the diverging features of the two product lines, particularly the iPad's multitasking capabilities.
Handoff makes it possible. When your Mac, iOS, or iPadOS devices are near each other, they can automatically pass what you're doing from one device to another. An icon representing the last app you were using will appear on your second device — in the Dock on your Mac or iPad or in the App Switcher on your iPhone.
I can see iPadOS developing in a direction that, for the most part, makes the experience for most users more or less indistinguishable from macOS — and in turn, makes using the two side by side more seamless than ever. But this absolutely doesn't mean iPadOS will behave like macOS under the hood.
The condition I used to detect IpadOS:
ua.toLowerCase().indexOf('macintosh') > -1 && navigator.maxTouchPoints && navigator.maxTouchPoints > 2
Unfortunately doing so via the User-Agent string alone doesn't seem to be possible anymore. This is a bit of an issue if you're server-side and need to share downloads differently as you mentioned in one of your comments.
However, the below should reliably detect iPads on the client-side:
const iPad = !!(navigator.userAgent.match(/(iPad)/)
|| (navigator.platform === "MacIntel" && typeof navigator.standalone !== "undefined"))
It avoids relying on touch events which will occur on Macs with touch screen monitors, and instead uses navigator.standalone
which is an iOS only property.
Combining quangh's answer and Michael Zaporozhets's answer to detect mobile devices including iPads.
detectMobile() {
let isMobile = RegExp(/Android|webOS|iPhone|iPod|iPad/i)
.test(navigator.userAgent);
if (!isMobile) {
const isMac = RegExp(/Macintosh/i).test(navigator.userAgent);
if (isMac && navigator.maxTouchPoints && navigator.maxTouchPoints > 2) {
isMobile = true;
}
}
return isMobile;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With