wx.saveImageToPhotosAlbum 保存图片失败
发布于 6 年前 作者 ming67 10228 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

 代码走到wx.saveImageToPhotosAlbum 没任何反应,

  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

//下载图片

share: function () {

let that = this;

wx.canvasToTempFilePath({

canvasId: ‘myCanvas’,

success: function (res) {

console.log(res.tempFilePath)

that.setData({

tempFilePath: res.tempFilePath

})

wx.saveImageToPhotosAlbum({

filePath: res.tempFilePath,

success: function success(res) {

wx.showModal({

title: ‘成功保存图片’,

content: ‘已成功为您保存图片到手机相册,请自行前往朋友圈分享’,

success: function () {

that.setData({

friendTrue:false

})

}

})

},

fail: function fail(e) {

wx.getSetting({

success: (res) => {

console.log(res);

console.log(res.authSetting[‘scope.writePhotosAlbum’]);

if (res.authSetting[‘scope.writePhotosAlbum’] == false) {

wx.openSetting({

success: (res) => {

console.log(res);

}

})

}

}

})

}

});

}

})

},

这个问题目前再iphone5.6.有问题, 我的手机是iPhone8就没有问题,再另外一个iphone8就有问题,不知道为啥,这段代码以前没有问题,最近才出现问题,不知道为啥,我一直没有动过

4 回复

麻烦提供出现问题的机型和微信版本,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

老哥,你现在点击保存,拒绝授权以后,再点击会opensetting吗?

用我的解决方法,代码如下

// 绑定tap点击事件

submit(){

    this.getAuth('scope.writePhotosAlbum')
        .then(() => {

            // 在这里处理接下里的流程


        }, ()=>{
           console.log('请开启保存到相册权限');
        })
}



// 小程序校验权限

getAuth(key){
    return new Promise((resolve, reject)=>{
        if(!ctx.isXCX){
            return resolve();
        }
 
        wx.getSetting({
            success(auth) {
                // 用户授权过
                if (auth.authSetting.hasOwnProperty(key)) {
                    // 拒绝
                    if(!auth.authSetting[key]){
                        wx.openSetting({
                            success: res => {
                                // 用户开启
                                if (res.authSetting[key]) {
                                    resolve();
                                } else {
                                    reject();
                                }
                            },
                            fail() {
                                reject();
                            }
                        })
                    } else {
                        // 成功授权
                        resolve();
                    }
                } else {
                    // 用户一次都没有授权过
                    wx.authorize({
                        scope: key,
                        success(res) {
                            // 成功授权
                            resolve();
                        },
                        fail() {
                            // 拒绝授权
                            reject();
                        }
                    })
                }
            }
        })
    })
},

老哥,问题解决了没有?我的也是这样,之前好好的,现在走到保存那直接就跳过了;授权提示框都没跳出来。解决了麻烦分享一下。多谢!!!

回到顶部