H5嵌入APP后,保存图片至相册(window.WebViewJavascriptBridge原生APP与H5之间交互)

原生APP跳转到H5页面时,往往需要携带一些用户信息,之前做法是在跳转的地址中拼接H5页面需要的参数,现在通过window.WebViewJavascriptBridge悄悄的进行数据交互。

需要在app里面测试才能看到效果

1.注册全局方法
export const savePhoto = (options) => {
    console.log(options)
    let params = '{}';
    if (typeof (options) == 'object') {
        params = JSON.stringify(options)
    }
    window.WebViewJavascriptBridge.callHandler(
        'savePhoto',
        encodeURIComponent(params),
        function (responseData) {
            if (options && options.onResponse) {
                options.onResponse(responseData);
            }
        }
    );
}
2.使用全局方法,保存图片至相册(以下是使用vue3点击事件)
const saveButton = url =>{
  const imgName = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."))
  savePhoto({
    url : url,
    name :imgName+index.value+'.png',
    onResponse : function (res) {
      const ress = JSON.parse(res);
      if (ress && ress.code == '200') {
        setTimeout(()=>{
          alert("保存图片成功") //可用组件,样式美化些
          index.value ++
        },500)
      }
    }
  })
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值