Introduction
Frontend projects sometimes need to identify the device type—for example, whether the visitor is using iOS or Android.
The problem with user-agent checks
Traditionally, an iOS check might inspect only the browser’s user agent:
1 | /iPhone|iPad|iPod/i.test(navigator.userAgent); |
This does not reliably identify newer iPads. Starting with iPadOS 13, an iPad can report its platform as MacIntel, causing it to be mistaken for a Mac.
Use a combined check instead:
1 | function getDeviceType(): 'Android' | 'IOS' | 'unknown' { |
Although iPadOS 13 and later can identify the device as MacIntel, an iPad still supports multitouch. Checking navigator.maxTouchPoints > 1 distinguishes it from a typical Mac.