javscript로 앱 버전에 따라 다르게 동작하는 로직을 짜야할때가 있다
navigater의 ugerAgent값으로 user의 플랫폼을 확인하여 분기해보자
코드 📃.js
const isApp = (/iphone|ipad|ipod|android/i.test(navigator.userAgent.toLowerCase()));
const isNewAppVer = isApp ? checkNewAppVer(curAppVer) : false;
const checkNewAppVer = (curAppVer) => {
const uaString = navigator.userAgent;
const isAndroid = uaString.match(/Android/i);
const isIos = uaString.match(/iPhone|iPad|iPod/i);
const SUPPORT_VER = { AOS: '200', IOS: '201' } // ex) vc 200, 2.0.1
// 앱 분기
const supportVer = isAndroid ? SUPPORT_VER[AOS] : SUPPORT_VER[IOS];
const currentVer = isAndroid ? curAppVer : curAppVer.replace(/\./g, '');
return currentAppVer >= supportAppVer;
}
if (isNewAppVer) {
// 새로운 내용 적용
} else {
// 구버전
}