在调用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)
}

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