h5页与ios通信
Posted junwu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了h5页与ios通信相关的知识,希望对你有一定的参考价值。
直接上代码 1 粘第一段
//ios 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 = ‘wvjbscheme://__BRIDGE_LOADED__‘; document.documentElement.appendChild(WVJBIframe); setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0) }
setupWebViewJavascriptBridge(function(bridge) { iapp.sidebar.delegate("li","touchend",function(event){ var $this = $(this); var index = $this.index(); var point = { 0:function(){ bridge.callHandler(‘CallHandlerID‘, {‘key‘: ‘患者‘}, function(response){ }) }, 1:function(){ bridge.callHandler(‘CallHandlerID‘, {‘key‘: ‘疾病‘}, function(response){ }) }, 2:function(){ bridge.callHandler(‘CallHandlerID‘, {‘key‘: ‘检测史‘}, function(response){ }) }, 3:function(){ bridge.callHandler(‘CallHandlerID‘, {‘key‘: ‘家族史‘}, function(response){ }) }, 4:function(){ bridge.callHandler(‘CallHandlerID‘, {‘key‘: ‘用药史‘}, function(response){ }) } } point[index](); }) })
需求还是挺简单的 点击了那个菜单就穿那个菜单名过去
https://github.com/marcuswestin/WebViewJavascriptBridge
以上是关于h5页与ios通信的主要内容,如果未能解决你的问题,请参考以下文章