Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined is not an object (evaluating '_expo.Permission.askAsync')

i don't know what's the problem exactly but when i click on the button to choose image that erreur fire in the console here's my code

_checkPermissions = async () => {
    try {
      const { status } = await Permission.askAsync(Permission.CAMERA);
      this.setState({ camera: status });
      const { statusRoll } = await Permission.askAsync(Permission.CAMERA_ROLL);
      this.setState({ cameraRoll: statusRoll });
    } catch (err) {
      console.log(err);
    }
  };
  findNewImage = async () => {
    try {
      this._checkPermissions();
      let result = await ImagePicker.launchImageLibraryAsync({
        mediaTypes: "Images",
        allowsEditing: true,
        quality: 1
      });

      if (!result.cancelled) {
        this.setState({
          image: result.uri
        });
      } else {
        console.log("cancel");
      }
    } catch (err) {
     // console.log(err);
    }
  };
like image 554
Ahmed Essaadi Avatar asked May 13 '19 23:05

Ahmed Essaadi


1 Answers

to me what solved it was importing the permissions and imagePicker like this:

import * as Permissions from 'expo-permissions';
import * as ImagePicker from 'expo-image-picker';

instead of this:

import Permissions from 'expo-permissions';
import ImagePicker from 'expo-image-picker';

And that's basically because there is no default export

like image 59
Abdelrhman Elmahdy Avatar answered Oct 07 '22 12:10

Abdelrhman Elmahdy