收藏
回答

wx.shareImageToGroup的问题?不可以和snapshot联合使用?

在调用snapshot生成图片后。直接调用wx.shareImageToGroup 会提示fail can only be invoked by user TAP gesture 。 这应该是个常见的需求啊。
PS:我就是在用户点击操作后执行的该操作,怎么会认定为不是用户主动触发的呢:


页面:

<button class="btn good-news" bind:tap="updateXiBaoImg" data-ind="{{idx}}">发送喜报</button>


js:

updateXiBaoImg() {
    const that = this
    // setTimeout(() => {
      this.createSelectorQuery()
        .select('#target')
        .node()
        .exec(res => {
          const node = res[0].node
          node.takeSnapshot({
            type: 'file',
            format: 'png',
            success: (res) => {
              const imagePath = res.tempFilePath
              console.info('snapshot: ', imagePath)
              // that.data.xibaoImg = imagePath
              wx.shareImageToGroup({
                imagePath: imagePath,
                needShowEntrance: false,
                complete(res) {
                  console.info('shareImageToGroup: ', imagePath)
                },
                fail(err){
                  console.error(err);
                }
              })
            },
            fail(res) {
              console.info('takeSnapshot fail: ', res)
              wx.showToast({
                title: '分享进度失败',
                icon: 'none'
              })
            }
          })
        })
    // }, 500)
  }


最后一次编辑于  2025-09-28
回答关注问题邀请回答
收藏

2 个回答

  • 金瓜兜儿
    金瓜兜儿
    2025-09-28

    可以提前通过takeSnapshot,生成图片的tempFilePath,点击分享的时候就直接使用tempFilePath就行。

    2025-09-28
    有用 1
    回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-09-28
    有用
登录 后发表内容