zoukankan      html  css  js  c++  java
  • h5与安卓、ios交互

    1.安卓交互

         h5调用安卓方法

           window.webview.xxx()

         安卓调用h5方法, 方法需要在全局注册

        

    window['showUnreadMsg'] = () => {
    	this.$nextTick(() => {
    		this.showUnreadMsg();
    	})
    }
    

      

     2. ios交互

        

    function setupWebViewJavascriptBridge(callback) {
      if (window.WebViewJavascriptBridge) {
        return callback(window.WebViewJavascriptBridge)
      }
      if (window.WVJBCallbacks) {
        return window.WVJBCallbacks.push(callback)
      }
      window.WVJBCallbacks = [callback]
      let WVJBIframe = document.createElement('iframe')
      WVJBIframe.style.display = 'none'
      WVJBIframe.src = 'https://__bridge_loaded__'
      document.documentElement.appendChild(WVJBIframe)
      setTimeout(() => {
        document.documentElement.removeChild(WVJBIframe)
      }, 0)
    }

      h5调用ios方法

       

    setupWebViewJavascriptBridge(function(bridge){
        bridge.callHandler('getPhoneNumber',(data) => {
            that.loginApp(data)	
        })
    })        

    ios调用h5方法, 同样需要全局注册

    setupWebViewJavascriptBridge(function(bridge){
      bridge.registerHandler('showUnreadMsg',(data,responseCallback)=>{
    	if(responseCallback){
    		that.showUnreadMsg();
    	}
      })
    })

      

  • 相关阅读:
    UVA 125 Numbering Paths
    UVA 515 King
    UVA 558 Wormholes
    UVA 10801 Lift Hopping
    UVA 10896 Sending Email
    SGU 488 Dales and Hills
    HDU 3397 Sequence operation
    数据库管理工具navicat的使用
    javascript封装animate动画
    关于webpack没有全局安装下的启动命令
  • 原文地址:https://www.cnblogs.com/THONLY/p/11303011.html
Copyright © 2011-2022 走看看