h5调oc 方法
<div id="btn">
<a class="a-btn" onclick="aBtn()">下载APP免费投广告</a>
</div>
<script>
var u = navigator.userAgent;
//申明交互
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) {
return callback(WebViewJavascriptBridge);
}
if (window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback);
}
window.WVJBCallbacks = [ callback ];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() {
document.documentElement.removeChild(WVJBIframe)
}, 0)
}
function aBtn () {
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
window.DDBridge.click();// 约定的事件
} else if (u.indexOf('iPhone') > -1) {//苹果手机
setupWebViewJavascriptBridge(function(bridge) {
//处理 js 调用 oc
bridge.callHandler('click',function(response) {// click约定的事件
});
});
}
}
</script>