1
votes

I am new to React native. I am using 'react-native-image-picker' for picking images either from Gallery or Camera. For Camera, it is working perfectly but in the case of the gallery if I deny permission even though I am able to get images from the gallery. What am I doing wrong?

My code is below:

  import ImagePicker from 'react-native-image-picker';

    <ActionSheet
       ref={o => this.ActionSheet = o}
       title={'Which one do you select?'}
       options={['Gallery', 'Camera', 'cancel']}
       cancelButtonIndex={2}
       destructiveButtonIndex={1}
       onPress={(index) => {
        if (index == 0) {
          this.handleChoosePhoto()
        } else if (index == 1) {
          this.launchCamera()
        }
     }}
  />

      handleChoosePhoto = () => {
        this.setState({
          loading: true,
        });
        const options = {
          noData: true,
        };

        ImagePicker.launchImageLibrary(options, response => {
          if (response.didCancel) {
            console.log('User cancelled image picker');
          } else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
            Linking.openSettings()
          } else if (response.customButton) {
            console.log('User tapped custom button: ', response.customButton);
            alert(response.customButton);
          } else {
            AsyncStorage.setItem('CandidatePhotoUrl', response.uri);
            this.setState({ photo: response });
          }
          this.setState({ loading: false })
        });
      };

    launchCamera = () => {
        this.setState({
          loading: true,
        });
        let options = {
          storageOptions: {
            skipBackup: true,
            path: 'images',
          },
        };
        ImagePicker.launchCamera(options, (response) => {
          console.log('Response = ', response);

          if (response.didCancel) {
            console.log('User cancelled image picker');
          } else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
            Linking.openSettings()
          } else if (response.customButton) {
            console.log('User tapped custom button: ', response.customButton);
            alert(response.customButton);
          } else {
            AsyncStorage.setItem('CandidatePhotoUrl', response.uri);
            const source = { uri: response.uri };
            console.log('response', JSON.stringify(response));
            this.setState({ photo: response });
          }
          this.setState({ loading: false })
        });

      }

info.plist is:

enter image description here

1
If you are in the simulator I would swear that all permissions are granted. No matter what you deny. - SmoggeR_js
I am checking in the real device. - Gulshan Kumar
Then are you testing it in Debug Mode? - SmoggeR_js
No, I am in normal mode. - Gulshan Kumar
are you saying about configuration? - Gulshan Kumar

1 Answers