判断是否是android,ios,qq,wetchat
export const Config = {}; Config.ua = navigator.userAgent.toLowerCase(); Config.isiOS=()=>{ return /(iphone|ipad|ipod|ios)/i.test(Config.ua) } Config.isAndroid=()=>{ return /(android)/i.test(Config.ua) } Config.isLaobaiAndroid = () => { return /laobaiapp android/.test(Config.ua); }; Config.isLaobaiiOS = () => { return /laobaiapp ios/.test(Config.ua) }; Config.isWeChat = () => { return /micromessenger/.test(Config.ua); }; Config.isQQ = () => { return /qq/.test(Config.ua); }; export default Config;
判断当前app的版本号
const getAppVerison = (expStr) => { if (expStr == null) return null; const ua = navigator.userAgent.toLowerCase(); const patt = new RegExp(expStr, "g"); let lastIndex = null; while ((patt.exec(ua)) != null) { lastIndex = patt.lastIndex } if (lastIndex == null) { return null } return ua.substr(lastIndex) };
对比app版本号,有时候版本不够需提示更新
export const compareVersionEle = (currVersion, targetVerison) => { if (!currVersion || !targetVerison) return false; const curr = currVersion.split(‘.‘); const target = targetVerison.split(‘.‘); for (let i = 0; i < curr.length; i++) { if (parseInt(curr[i]) > parseInt(target[i])) { return true } if (parseInt(curr[i]) < parseInt(target[i])) { return false } //相等继续 //parseInt(curr[i]) == parseInt(target[i]) continue } return true };