Kanzafarov S.
Kanzafarov S.

Reputation: 43

React native (ios). "saveToCameraRoll" error - "PHPhotosErrorDomain error -1"

When I try to save an image to the phone (emulator IPhone 11 - iOS 13.1) gallery:

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);
});

, it gives me an error:

err: [Error: The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)]

I added these lines to the file "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>

And run command in "ios" folder:

pod update
pod install

But the error still remains. Is there anything I have to do to clean up the error?

Upvotes: 3

Views: 3896

Answers (2)

TheIndianRaj
TheIndianRaj

Reputation: 1

If this helps someone,

I got the same error in the React Native Cameraroll version 4.1.2. (iOS)

"react-native": "0.63.3".

I solved the issue by prefixing "file://" in the image path for saveToCameraRoll/save method.

Upvotes: 0

Lucas Ferrarezi
Lucas Ferrarezi

Reputation: 94

I just faced the same situation, here's how i solved it:

I've downloaded the file using 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
    })

with the file saved locally on your app we can now call CameraRoll to save the file:

CameraRoll.saveToCameraRoll(file.path())
.then(Alert.alert("Done!", "Your file has been saved."))

Upvotes: 1

Related Questions