公司小程序是用uniapp开发的,使用saveImageToPhotosAlbum()保存,在微信开发者工具中和真机调试都能正常运行,代码如下,在安卓真机上可以生成海报但是无法保存,苹果手机上直接无法生成海报。查看官网文档需要在小程序管理后台配置downloadFile中添加域名。如果不添加,控制台会提示,但是控制台没有提示消息,查阅相关文档,需要在开发者工具中取消下面校验合法域名选项,但是重启项目依然没有效果。最后在manifest.json中发现没勾选,勾选以后重启项目,果然在控制台报错了,然后在微信小程序后台开发设置中添加域名后问题解决了。
wx.getImageInfo({ src: path, success: sres => { //console.log(sres.path); wx.saveImageToPhotosAlbum({ filePath: sres.path, success: res => { wx.setNavigationBarColor({ frontColor: "#000000", backgroundColor: "#ffffff", animation: { duration: 1 } }); this.isPreviewImg = false; wx.showToast({ title: "保存成功", duration: 1000, icon: "success", mask: true }); }, fail: res => { wx.setNavigationBarColor({ frontColor: "#000000", backgroundColor: "#ffffff", animation: { duration: 1 } }); this.isPreviewImg = false; wx.showToast({ title: "保存失败", duration: 1000, icon: "none", mask: true }); } }); } })