{"errMsg":"saveImageToPhotosAlbum:fail No Permission","errCode":12,"code":12} , 保存失败
uniapp vue2 在app环境下 调用saveImageToPhotosAlbum提示没有权限,uni.previewImage 本身自带的保存图片也无法保存
机型红米k70 澎湃os 1.0.20.0
hbuilder版本4.66 升级到4.75也不行
想问下这个问题有没有遇到过 该如何解决
uni.previewImage({
current: currentIndex >= 0 ? currentIndex : 0,
urls: urls,
indicator: 'number',
loop: false,
longPressActions: {
itemList: ['保存图片', '分享'],
itemColor: '#d60000',
success: data => {
console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
/* 保存图片到系统相册 */
plus.nativeUI.closePreviewImage();
if (data.tapIndex == 0) {
// 保存图片
this.saveImageToAlbum(urls[data.index]);
} else if (data.tapIndex == 1) {
// 分享功能
this.shareImage(urls[data.index]);
}
},
fail: err => {
console.log(err.errMsg);
}
}
})
// 保存图片到相册
saveImageToAlbum(filePath) {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success: res => {
plus.nativeUI.toast("保存成功", { background: "#c3002f" });
},
fail: err => {
console.log(err, "保存失败");
// 如果是权限问题,引导用户去设置
if (err.errMsg && err.errMsg.includes('permission')) {
uni.showModal({
title: '权限提示',
content: '需要相册权限才能保存图片,请在设置中开启',
confirmText: '去设置',
success: (res) => {
if (res.confirm) {
// #ifdef APP-PLUS
plus.runtime.openURL('package:' + plus.runtime.appid);
// #endif
}
}
});
} else {
uni.showToast({
title: '保存失败',
icon: 'none'
});
}
}
})
}
1 个回复
DCloud_UNI_yuhe
去看一下设置中权限呢?