H5与原生app交互
原生调h5方法:
h5:注册方法,绑定在windowns上:如windown[方法名] = ()=>{}
h5调原生方法,需要区分安卓和ios
/** 获取设备系统类型 */
export const LoginPhoneType = () => {
var sUserAgent, isIOS, isAndroid, isIpad;
sUserAgent = navigator.userAgent.toLowerCase();
isIOS = sUserAgent.match(/iphone os/i) == 'iphone os';//|| deviceInfo.systemName === 'iPhone';
isAndroid = sUserAgent.match(/android/i) == 'android';//|| deviceInfo.systemName === 'Android';
isIpad = sUserAgent.match(/ipad/i) == "ipad";
if (isAndroid) {
return 'android';
} else if (isIOS || isIpad) {
return 'ios';
} else {
return null;
}
};
export const getAddress = () => {
const jzbank = window.jzbank;
if (!window.webkit && !jzbank) return;
const platform = LoginPhoneType();
if (platform === "ios") window.webkit.messageHandlers.getAddress.postMessage();
else if (platform === "android") jzbank.getAddress();
};
标签:jzbank,原生,const,app,sUserAgent,H5,return,android,交互
From: https://www.cnblogs.com/wszzj/p/17485999.html