判断IOS系统
function getIsIOS(){
const UA = navigator.userAgent.toLowerCase();
const isAndroid = /android|adr/gi.test(UA);
const isIos = /iphone|ipod|ipad/gi.test(UA) && !isAndroid;
return isIos
}
判断iPhoneX及以后版本
function isIphoneX() {
const xSeriesConfig = [
{
devicePixelRatio: 3,
width: 375,
height: 812,
},
{
devicePixelRatio: 3,
width: 414,
height: 896,
},
{
devicePixelRatio: 2,
width: 414,
height: 896,
},
]
if (typeof window !== 'undefined' && window) {
const isIOS = /iphone/gi.test(window.navigator.userAgent)
if (!isIOS) {
return false
}
const { devicePixelRatio, screen } = window
const { width, height } = screen
return xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height)
}
return false
}
判断微信环境
export function getIsWeixin() {
const ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
}
return false;
}
判断网络
function isOnLine() {
function onLine(callback) {
var img = new Image();
img.src = 'https://www.baidu.com/favicon.ico?_t=' + Date.now();
img.onload = function () {
if (callback) callback(true)
};
img.onerror = function () {
if (callback) callback(false)
};
}
onLine(function (flag) {
if (flag) {
} else {
window.LeKeBridge.sendMessage2Native("toast", "网络断开");
}
})
}