浏览器上:
window.WebViewJavascriptBridge.callHandler("startServiceCenter")
安卓上:
window.connectWebViewJavascriptBridge((bridge) => {
bridge.callHandler('startServiceCenter', {data: {}}, (response) => {})
})
ios上:
window.setupWebViewJavascriptBridge((bridge) => {
bridge.callHandler('postDeviceInfo', {}, (responseData) => {
requestBasic({
method: 'post',
url: '/log/ua',
data: Object.assign(responseData, info)
})
})
})
检查设备的:
export function checkIsAndroid () {
const ua = navigator.userAgent.toLowerCase()
return ua.indexOf('android') > -1
}
export function checkIsIos () {
const ua = navigator.userAgent.toLowerCase()
return ua.indexOf('iphone') > -1 || ua.indexOf('ipad') > -1
}
export function checkIsWechat () {
const ua = navigator.userAgent.toLowerCase()
return ua.match(/MicroMessenger/i) !== null
}
export function checkIsAppNameApp () {
const ua = navigator.userAgent.toLowerCase()
return (/appname/i).test(ua)
}
export function getOSType () {
if (checkIsAppNameApp()) {
return 'app'
}
if (checkIsWechat()) {
return 'wechat'
}
if (checkIsAndroid()) {
return 'android'
}
if (checkIsIos()) {
return 'ios'
}
return 'web'
}
Navigator 对象包含有关浏览器的信息
userAgent 返回由客户机发送服务器的 user-agent 头部的值。