Реагировать на родную (ios). Ошибка «saveToCameraRoll» - «Ошибка PHPhotosErrorDomain -1» - PullRequest
1 голос
/ 15 марта 2020

Когда я пытаюсь сохранить изображение в телефоне (эмулятор 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

Но ошибка все еще остается. Что мне нужно сделать, чтобы исправить ошибку?

1 Ответ

1 голос
/ 23 марта 2020

Я только что столкнулся с той же ситуацией, вот как я решил ее:

Я скачал файл, используя 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."))
...