1. 程式人生 > >APP中關於Android和IOS與網頁交互

APP中關於Android和IOS與網頁交互

frame win android rem androi create out eth sta

安卓交互:

    //安卓js代碼start
    function bntcat(){
        if(isAndroid){
            musicPause()
        }
        var str = ‘{"tips":2018,"type":3}‘;
        JsCallback.jsMethod(str);
    }
    //安卓js代碼end

IOS交互:

    //ios js代碼start
    /****************************ios固定寫法start**********************************/
    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)
    }
    /****************************ios固定寫法end**********************************/
    setupWebViewJavascriptBridge(function (bridge) {
        $(".xxxxxx").click(function(){
            var id= $(this).data("id"),
            str = ‘{"tips":2018,"type":1,"gid":‘+id+‘}‘;           
            bridge.callHandler(‘nhjGoodsDetails‘, str, function (responseData) {})
        });
        bridge.registerHandler(‘miusicPlay‘, function (data, responseCallback) {
            $("#playAudio").addClass(‘on‘);
            document.getElementById("myaudio").play();
            responseCallback({‘userId‘: ‘123456‘, ‘blog‘: ‘miusicPlay‘})
        });
        bridge.registerHandler(‘miusicPause‘, function (data, responseCallback) {
            $("#playAudio").removeClass(‘on‘);
            document.getElementById("myaudio").pause();
        })
    });
    //ios js代碼end

  

APP中關於Android和IOS與網頁交互