登陆小程序后台https://mp.weixin.qq.com/更新一下用户隐私协议
要填写获取相册权限是干什么用的代码里面也要判断用户是否有相册权限
不然用户一脸懵逼,只知道图片保存无反应获取失败
/**
* 下载图片
* @param {*} url
*/
downloadImg(url, callback) {
// 首先下载图片
uni.downloadFile({
url,
success: downloadResult => {
if (downloadResult.statusCode === 200) {
// 下载成功,保存图片到系统相册
uni.saveImageToPhotosAlbum({
filePath: downloadResult.tempFilePath,
success: () => {
callback && callback()
uni.showToast({
title: '图片保存成功',
icon: "none"
});
},
fail: (err) => {
console.log('err:', err);
uni.showToast({
title: '图片保存失败',
icon: 'none'
});
}
});
}
},
fail: () => {
uni.showToast({
title: '图片下载失败',
icon: 'none'
});
}
});
},
getAlbumPermissions(url, callback) {
let that = this
uni.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success(res) {
that.downloadImg(url, callback)
},
fail() {
uni.showModal({
content: '请允许相册权限,拒绝将无法正常使用小程序',
showCancel: false,
success() {
uni.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
} else {
console.log('获取权限失败')
}
}
})
}
})
}
})
} else {
that.downloadImg(url, callback)
}
}
})
},