webview跳转回小程序携带base64保存图片异常报错 {"errMsg": "saveImageToPhotosAlbum:fail save fail:Error Domain=PHPhotosErrorDomain Code=3302 "(null)""}
安卓和编辑器都没问题,但是ios真机就是会报这个错
bindmessage(e) {
let newBase64 = e.detail.data[0].replace(/[\r\n]/g, '').substring('data:image/png;base64,'.length);
// Logging the base64 data
// Decoding base64 to a binary buffer
const buffer = uni.base64ToArrayBuffer(newBase64);
// Creating a temporary file path
const tempFilePath = `${uni.env.USER_DATA_PATH}/temp_${Date.now()}.png`;
// Writing the binary buffer to a temporary file
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.writePhotosAlbum']) {
uni.getFileSystemManager().writeFile({
filePath: tempFilePath,
data: buffer,
encoding: 'binary',
success: res => {
console.log('Temporary file saved successfully:', tempFilePath);
// Saving the temporary file to the photo album
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: res => {
console.log('Image saved to album:', res);
uni.showToast({
title: '保存成功',
icon: 'none'
})
},
fail: err => {
console.error('Failed to save image to album:', err);
uni.showToast({
title: '保存失败,请重试',
icon: 'none'
})
}
})
},
fail: err => {
console.error('Failed to save temporary file:', err);
}
});
} else {
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,
success() {
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showModal({
title: '提示',
content: '获取权限成功,再次保存图片即可成功',
showCancel: false,
})
} else {
wx.showModal({
title: '提示',
content: '获取权限失败,无法保存到相册',
showCancel: false,
})
}
},
complete(comp) {
console.log("complete", comp)
}
})
}
})
}
}
})
},
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。