返回
appGetBack 就是ios或安卓定义好的方法
// 返回
goBack() {
// 判断环境
let ran = navigator.userAgent;
let isAndroid = ran.indexOf('Android') > -1 || ran.indexOf('Linux') > -1;
let isIOS = !!ran.match(/(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isAndroid) {
// 安卓环境
window.android.appGetBack();
return;
}
if (window.webkit != undefined && isIOS) {
// IOS环境
window.webkit.messageHandlers.appGetBack.postMessage(null);
return;
}
},
传参
receivePrize 就是ios或安卓定义好的方法
//去领取(跳转到app)
gotoCollect() {
geCustomerService().then(res => {
let data = res.data;
let ran = navigator.userAgent;
let isAndroid = ran.indexOf("Android") > -1 || ran.indexOf("Linux") > -1;
let isIOS = !!ran.match(/(i[^;]+;( U;)? CPU.+Mac OS X/);
let status = data.status === 0 //0=在线
if (isAndroid) {
try {
// 安卓app环境
window.android.receivePrize(JSON.stringify(data));
} catch (e) {
location.href = `https://xxxx.com/im/xxx/${data.id}/1/${data.nickname}/${status}`
}
}
if (window.webkit !== undefined && isIOS) {
window.webkit.messageHandlers.receivePrize.postMessage({ ...data });
}
})
},