当我试图将图像保存到电话(模拟器IPhone 11 - iOS 13.1)库时:
import CameraRoll from "@react-native-community/cameraroll";
...
CameraRoll.saveToCameraRoll('https://example.com/images/1.jpg', 'photo')
.then(() => {
alert('Saved to photos');
})
.catch((err) => {
console.log('err:', err);
});
它给了我一个错误:
错误:错误:操作无法完成。(PHPhotosErrorDomain错误-1.)
我将这些行添加到文件“Info.plist”中:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app requires access to the photo library</string>
并在"ios“文件夹中运行命令:
pod update
pod install
但错误仍然存在。我需要做些什么来纠正错误吗?
发布于 2020-03-23 15:02:32
我只是面对同样的情况,我就是这样解决的:
我已经使用rn-fetch-blob
下载了这个文件
let file
RNFetchBlob
.config({
fileCache: true,
appendExt: path.substring(path.lastIndexOf('.')+1, path.length)
//get the file's extension from the URL it's coming from and append to the file name that RNFectchBlob will create locally
})
.fetch('GET', path) //GET request to URL which has your file
.then((res) => {
file = res //var 'file' is the temp object which contains all data from our file
})
在应用程序上本地保存文件之后,我们现在可以调用CameraRoll
来保存该文件:
CameraRoll.saveToCameraRoll(file.path())
.then(Alert.alert("Done!", "Your file has been saved."))
发布于 2022-03-11 14:22:43
如果这对某人有帮助,
我在版本4.1.2中也出现了同样的错误。(iOS)
“反应-本地人”:"0.63.3“。
我通过为saveToCameraRoll/file://“方法在图像路径中添加前缀解决了这个问题。
https://stackoverflow.com/questions/60688549
复制相似问题