js判斷是不是app,及版本號

判斷是不是android,ios,qq,wetchatandroid

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的版本號ios

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版本號,有時候版本不夠需提示更新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
};
相關文章
相關標籤/搜索