个人记录:老版JSBridge使用方法

438 阅读1分钟

#创建JSBridge对象

export const = jrBridgeDefer = jrJsBridge.onReady()

1、返回挽留弹框

jsToGetResp()是个客户端的通信方法
jrBridgeDefer.then(res => {
      res.jsToGetResp(d => {                          
          d = typeof d === 'object' ? d : JSON.parse(d);
          if (d && d.type === '52') {
            // alert('1212 -> ' + JSON.stringify(d));
            // 业务逻辑
          }
        },
        {
          type: '52',
          registerUrl: window.location.href
        }
      );
    });

#若业务逻辑没有执行,可能是多个JSBridge冲突了,可利用setTimeOut()

try {
    setTimeout(()=>{
      jrBridgeDefer.then(res => {
          res.jsToGetResp(d => {
              d = typeof d === 'object' ? d : JSON.parse(d);
              if (d && d.type === '52') {
                // alert('1212 -> ' + JSON.stringify(d));
                // 业务逻辑
                this.modal.stayShow = true;
              }
            },
            {
              type: '52',
              registerUrl: window.location.href
            }
          );
        });
    },900);
  } catch (e) {
        console.log(e)
  }

2、关闭webview

jrBridgeDefer.then(function (res) {
    this.jsToNaClose()
})