在某一个页面使用skyline下载海报时,开发工具提示takeSnapshot:fail webview renderer is not supporte,需要我将小程序的线上最低基础库改成2.29.2才能下载吗?
page.json的代码为:"navigationBarTitleText": "详情",
"usingComponents": {},
"renderer": "skyline",
"navigationStyle":"custom",
"componentFramework":"glass-easel"
app.json的部分代码为:
"lazyCodeLoading": "requiredComponents",
"rendererOptions": {
"skyline": {
"defaultDisplayBlock": true,
"defaultContentBox": true
}
}
page.js下载海报的代码为:
this.createSelectorQuery().select("#view")
.node().exec(res => {
const node = res[0].node
node.takeSnapshot({
// type: 'file' 且 format: 'png' 时,可直接导出成临时文件
type: 'arraybuffer',
format: 'png',
success: (res) => {
console.log(123)
const f = `${wx.env.USER_DATA_PATH}/hello.png`
const fs = wx.getFileSystemManager();
fs.writeFileSync(f, res.data, 'binary')
wx.showToast({
title: '保存成功'
})
wx.saveImageToPhotosAlbum({
filePath: f,
success() {
wx.showToast({
title: '已保存到相册',
icon: 'success',
duration: 2000
})
},
fail(err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
that.secondGetPhoteAuthor();
} else {
showToast("您已拒绝授权相册权限,请截屏保存分享");
}
},
complete() {
wx.hideLoading()
}
})
},
fail(res) {
console.log("takeSnapshot fail:", res)
wx.hideLoading()
}
})
})
这个错误是因为编辑器的渲染模式还是 webview模式导致的。参考文档的方法给线上版本开启skyline渲染引擎:https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/skyline/migration/release.html#%E5%8F%91%E5%B8%83%E4%B8%8A%E7%BA%BF