Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 리액트 네이티브
- React
- fire base
- img upload
- 에러
- react native font
- 리엑트 네이티브 아이콘
- PongWorld
- aws bucket 정책
- 백준
- react native picker
- firebase 라이브러리
- AWS
- babel.config.js
- s3 upload
- GIT
- 리액트
- Project
- 문자열 대소문자 구별
- react native
- Next.js
- 리액트 네이티브 에러
- 문자열 대소문자
- react native 개발
- error
- js
- Access Key 생성
- react native 세팅
- AWS Access Key
- react native CLI
Archives
- Today
- Total
밝을희 클태
[ JS ] iPad safari에서 모바일 체크하기 본문
애플에서 iPad의 userAgent를 Mac이랑 통합을 해버려 아래의 코드만으로 ipad 인지 체크를 할 수 없다.
/iPad/.test(navigator.userAgent);
실제로 userAgent를 확인해 보면 useAgent에 iPad가 사라져 있다.
- iPad - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15
- MacBook - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15
chrome에서는 알아서 처리를 해서 잘 되는데 safari에서는 따로 설정을 추가해줘야 한다.
navigator의 maxTouchPoints는 스크린의 최대 터치 가능 포인트 수를 말하는데 일반적인 데스크톱의 경우 0이 나오고 iPad의 경우 5가 나온다.
maxTouchPoints가 있을 때 iPad 체크를 하는데 여기서 Macintosh와 iPad를 함께 검사를 해주는 이유는 safari에서는 Macintosh로 나오지만 chrome에서는 iPad로 나오기 때문에 두 가지 경우를 체크를 해줘야 한다.
if (navigator.maxTouchPoints > 1) { const isIPad = /Macintosh|iPad/.test(navigator.userAgent); if (isIPad) return true; return false; }
전체코드
export function isMobile() { if (typeof window !== 'undefined') { if (navigator.maxTouchPoints > 1) { const isIPad = /Macintosh|iPad/.test(navigator.userAgent); if (isIPad) return true; return false; } return /Mobi|Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } return false; }
'KEYNUT 프로젝트' 카테고리의 다른 글
[ AWS ] CloudFront를 활용해 S3 GET요청 최적화 (0) | 2024.08.18 |
---|---|
[ Next.JS ] 이미지 슬라이더(image-slider) UX 개선 (0) | 2024.08.18 |
[ Next.JS ] 배포 환경에서 주문형 재검증(On-demand Revalidation)이 안된다 (0) | 2024.08.03 |
[ JavaScript ] 핀치 줌 구현하기! (0) | 2024.07.19 |
[ Next.JS ]상품 업로드, 수정, 조회 로직 (0) | 2024.07.16 |