这里用的是 callapp-lib插件 我看了网上一些跳转操作 也可以有location.href 和iframe
- 这个插件在定义callback时候就不再执行fallback了 但appStore还是会打开 还有超过了timeout定义的时间还是会打开 所以这里安卓和ios是分开做的
- 所以 timeout设置合理的时间 只要超时就会打开fallback 或者appstore
import CallApp from "callapp-lib";
export const isNav = (() => {
const userAgent = navigator.userAgent.toLowerCase();
const isWechat = userAgent.indexOf('micromessenger') !== -1;
const isIos = /iphone|ipod|ipad/.test(userAgent);
const isAndroid = /android/.test(userAgent);
return { isWechat, isIos, isAndroid }
})()
const iosOption: any = {
scheme: { protocol: '' },
fallback: ''
}
const andOption: any = {
scheme: { protocol: 'app://xxxx', host: 'xxxx' },
fallback: '',
}
export const handleOpenApp = (_props = { form: '' }) => {
if (isNav.isWechat) {
alert('请在浏览器中打开');
} else {
const isOp = isNav.isIos ? iosOption : isNav.isAndroid ? andOption : {}
const callLib = new CallApp({
timeout: 2000,
appstore: '',
...isOp
});
if (isNav.isIos) {
callLib.open({
param: { ..._props },
path: _props?.form
});
} else if (isNav.isAndroid) {
callLib.open({
param: { ..._props },
path: _props?.form
});
}
}
}