首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应本机(ios)。"saveToCameraRoll“错误- "PHPhotosErrorDomain错误-1”

反应本机(ios)。"saveToCameraRoll“错误- "PHPhotosErrorDomain错误-1”
EN

Stack Overflow用户
提问于 2020-03-15 00:09:06
回答 2查看 2.2K关注 0票数 3

当我试图将图像保存到电话(模拟器IPhone 11 - iOS 13.1)库时:

代码语言:javascript
运行
复制
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”中:

代码语言:javascript
运行
复制
<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“文件夹中运行命令:

代码语言:javascript
运行
复制
pod update
pod install

但错误仍然存在。我需要做些什么来纠正错误吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-03-23 15:02:32

我只是面对同样的情况,我就是这样解决的:

我已经使用rn-fetch-blob下载了这个文件

代码语言:javascript
运行
复制
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来保存该文件:

代码语言:javascript
运行
复制
CameraRoll.saveToCameraRoll(file.path())
.then(Alert.alert("Done!", "Your file has been saved."))
票数 1
EN

Stack Overflow用户

发布于 2022-03-11 14:22:43

如果这对某人有帮助,

我在版本4.1.2中也出现了同样的错误。(iOS)

“反应-本地人”:"0.63.3“。

我通过为saveToCameraRoll/file://“方法在图像路径中添加前缀解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60688549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档