码迷,mamicode.com
首页 > 移动开发 > 详细

h5页与ios通信

时间:2017-02-04 16:27:44      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:log   一段   key   append   通信   remove   handle   ade   turn   

直接上代码 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通信

标签:log   一段   key   append   通信   remove   handle   ade   turn   

原文地址:http://www.cnblogs.com/junwu/p/6365617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!