React-Native-Camera Error when take photo with modified flashMode attribute

374 views Asked by At

I am getting the following error when trying to take photo with flashMode attribute modified:

{ NSLocalizedDescription: 'Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x170440210 {Error Domain=NSOSStatusErrorDomain Code=-16800 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-16800), NSLocalizedDescription=The operation could not be completed}' } } 2017-09-12 00:08:29.907053-0300 GimenesApp[1936:765074] { [Error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x170440210 {Error Domain=NSOSStatusErrorDomain Code=-16800 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-16800), NSLocalizedDescription=The operation could not be completed}]

Here is the piece of code that I am using:

<Camera
    captureTarget={Camera.constants.CaptureTarget.disk}
    ref={(cam) => {
      this.camera = cam;
    }} 
    flashMode={this.state.flashMode}>
    <Button onPress={this.takePicture.bind(this)} transparent 
      <Icon name="ios-radio-button-off" />
    </Button>
</Camera>
1

There are 1 answers

0
Luis Antonio Pestana On BEST ANSWER

So, I solved this error removing two calls to setState

Here is my take photo method:

  takePicture() {
    const options = {};
    this.camera.capture({metadata: options})
      .then((data) => {
        this.setState({
          PHOTO_PATH: data.path,
          IS_NOT_PHOTO_TAKE: false
        });
      })
      .catch(err => {
        console.error(err)
      });
  };

Before, I was setting the state twice in my takePicture method. I just moved the outside setState and the error is gone.

I do not know why, but now, it is working.

If anyone have an explanation to this error, please, share with us.