当我尝试将图像保存到手机(模拟器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);
});
,它给我一个错误:
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
但是错误仍然存在。我有什么要清理的错误吗?
答案 0 :(得分:1)
我只是面临相同的情况,这是我如何解决的方法:
我已经使用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."))