ua.ts 657 B

123456789101112131415161718192021
  1. export const isIOS = () => {
  2. // Client-only: SSR should always return false.
  3. if (!import.meta.client) return false
  4. try {
  5. const ua = (navigator.userAgent || '').toLowerCase()
  6. if (/iphone|ipad|ipod/.test(ua)) return true
  7. // iPadOS 13+ may report itself as "Macintosh" in desktop mode.
  8. // Detect it by combining platform + touch capability.
  9. const nav = navigator as Navigator & { maxTouchPoints?: number }
  10. const platform = (nav.platform || '').toLowerCase()
  11. const touchPoints = Number(nav.maxTouchPoints || 0)
  12. if (platform === 'macintel' && touchPoints > 1) return true
  13. }
  14. catch {
  15. // ignore
  16. }
  17. return false
  18. }