微信jssdk ios微信内部自定义分享失效,安卓正常

微信内部分享onMenuShareTimeline、onMenuShareAppMessage在ios系统中自定义内容出不来,安卓分享是没有问题的,这是怎么回事儿?
代码如下:

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
      wx.config({
          debug: false,
          appId: '<?php echo $signPackage["appid"];?>',
          timestamp: '<?php echo $signPackage["timestamp"];?>',
          nonceStr: '<?php echo $signPackage["noncestr"];?>',
          signature: '<?php echo $signPackage["signature"];?>',
          jsApiList: [
              'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'hideAllNonBaseMenuItem'
          ]
      });
</script>
<script>
      {if !empty($share_data)}
      wx.ready(function () {
              
          // 在这里调用 API
          wx.onMenuShareTimeline({
              title: '<?php echo $share_data["title"];?>', // 分享标题
              desc: '<?php echo $share_data["desc"];?>', // 分享描述
              link: '<?php echo $share_data["url"];?>', // 分享链接
              imgUrl: '<?php echo $share_data["imgurl"];?>', // 分享图标
              success: function () {
//                if (share_success != undefined) {
                  share_success();
//                }
              },
              cancel: function () {
//                if (share_cancel != undefined) {
                  share_cancel();
//                }
              }
          });

          wx.onMenuShareAppMessage({
              title: '<?php echo $share_data["title"];?>', // 分享标题
              desc: '<?php echo $share_data["desc"];?>', // 分享描述
              link: '<?php echo $share_data["url"];?>', // 分享链接
              imgUrl: '<?php echo $share_data["imgurl"];?>', // 分享图标
              type: 'link', // 分享类型,music、video或link,不填默认为link
              dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
              success: function () {
//                if (share_success != undefined) {
                  share_success();
//                }
              },
              cancel: function () {
//                if (share_cancel != undefined) {
                  share_cancel();
//                }
              }
          });
          wx.onMenuShareQQ({
              title: '<?php echo $share_data["title"];?>', // 分享标题
              desc: '<?php echo $share_data["desc"];?>', // 分享描述
              link: '<?php echo $share_data["url"];?>', // 分享链接
              imgUrl: '<?php echo $share_data["imgurl"];?>', // 分享图标
              type: 'link', // 分享类型,music、video或link,不填默认为link
              dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
              success: function () {
//                if (share_success != undefined) {
                  share_success();
//                }
              },
              cancel: function () {
//                if (share_cancel != undefined) {
                  share_cancel();
//                }
              }
          });
      });
      wx.error(function (res) {
//        alert(res.errMsg);
      });
      {else}
      wx.ready(function () {
          wx.hideAllNonBaseMenuItem();
      });
      {/if}
</script>
阅读 13.1k
10 个回答

解决了,link带的url是要带http的地址,现在我改成window.location.href,ios正常了

看下图标大小 记得ios分享图标不能超过32K

// 打开控制台运行,亲 (这是一段神奇的代码):
document.querySelector("button[data-id=\"1020000009688383\"][class=\"like\"]").click();

还有一个原因会造成答主的问题:link参数带中文或者特殊字符
带中文的url在安卓中应该也是会出问题的,但是安卓会自动encodeURIComponent(),而ios不会

debug打开,看看报错。

新手上路,请多包涵

用微信开发工具看看,是不是存在config的报错

新手上路,请多包涵

楼主解决了吗?遇到了同样的问题。

你可以让你用ios系统的那个微信重新安装一下或者重新登录一下账号 看看这样行吗

const userAgent = global.navigator.userAgent;
const inIOS = /iPhone|iPad|iPod/i.test(userAgent);
// 判断是否为ios微信
const location = global.location
export default {

beforeRouteEnter(to, from, next) {
    // XXX: 修复iOS版微信HTML5 History兼容性问题
        if (inIOS && to.path !== location.pathname) {
            // 此处不可使用location.replace
            location.assign(to.fullPath)
        } else {
            next()
        }


},

}

也遇到一样问题,安卓可以 ,ios不行,后面修改了link链接为静态地址,就可以了。应该是link地址不要包含特殊字符。

<?php echo $share_data["title"];?>你这个传值方式肯定不对,控制器assign传值都行

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题