网上说wx.openSetting已经废弃了,但又有说法是在点击事件的showModal的回调里可以用。
我在点击事件的showModal的回调里用wx.openSetting,真机上可以,模拟器上又报错。
实在是一头雾水,wx.openSetting到底能不能用啊?
其实,我就是要实现的保存海报功能,下面代码里用到wx.openSetting,请问下面这种代码的实现方法可以吗?
saveImage() {
wx.canvasToTempFilePath({
canvasId: ‘canvas’,
success(res) {
wx.getSetting({
success: (auth) => {
if (!auth.authSetting[‘scope.writePhotosAlbum’]) {
wx.authorize({
scope: ‘scope.writePhotosAlbum’,
success() {
console.log(“authorize”, res)
},
fail() {
wx.showModal({
title: ‘提示’,
content: ‘若点击不授权,将无法使用保存图片功能’,
cancelText: ‘不授权’,
cancelColor: ‘#999’,
confirmText: ‘授权’,
confirmColor: ‘#f94218’,
success(res) {
if (res.confirm) {
wx.openSetting()
} else if (res.cancel) {
console.log(‘用户点击取消’)
}
}
})
}
})
} else {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
wx.showToast({
title: ‘保存成功!’,
icon: ‘success’
})
},
fail(res) {
wx.showToast({
title: ‘保存失败,请允许保存相册权限’,
icon: ‘none’
})
}
})
}
}
})
}
})
}