为了账号安全,请及时绑定邮箱和手机立即绑定

js调用OC,报错'messageHandlers' of undefined

js调用OC,报错'messageHandlers' of undefined

长风秋雁 2019-03-21 18:15:51
我是前端js,需要通过OC调用安卓和ios的方法传webSend传4个参数,他们做分享功能,然后返回我是不是分享成功了。网上查了方法,但是报错 Cannot read property 'messageHandlers' of undefined, Cannot read property 'android' of undefined,不知道是哪里的问题<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <meta http-equiv="X-UA-Compatible" content="ie=edge">    <title>Document</title></head><body>    <button type="button" onclick="shareInformation()">分享</button></body><script>    function callback(data) {       //分享结果    }    function shareInformation() {        var lcon = {            title: document.title,            content: '分享的内容',            url: window.location.href,            imageUrl: 'https://www.baidu.com/',            cb: 'callback'        }        window.webkit.messageHandlers.webSend.postMessage(lcon);        android.webSend(lcon);    }</script></html>
查看完整描述

1 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

你在哪里看的报错,浏览器么,这个是说没有定义,这两个是安卓那边的方法吧,浏览器肯定会报错的,你要把html放到native里面,再看看会不会报错
双端兼容:dsbridge

查看完整回答
反对 回复 2019-04-14
  • 1 回答
  • 0 关注
  • 3525 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号