ReferenceError: Не удается найти переменную: Permissions и ReferenceError: Не удается найти переменную: ImagePicker - PullRequest
1 голос
/ 20 июня 2019

Я выбросил свой реактивный проект и тестирую его в Android Studio.Тем не менее, я получаю сообщение об ошибке:

ReferenceError: Не могу найти переменную: Permissions ReferenceError: Не могу найти переменную: ImagePicker

У меня есть кнопка загрузки, которая позволяет пользователю сделать снимокс их камерой и загрузите изображение.

Это собственный код для функции загрузки:

import React from "react";
import { TextInput, ActivityIndicator, Image, TouchableOpacity, View, Text, StyleSheet } from "react-native";
import { f, auth, database, storage } from "../config/config.js";
import UserAuth from "../components/auth.js";


    _checkPermissions = async () => {
        const { status } = await Permissions.askAsync(Permissions.CAMERA);
        this.setState({
            camera: status
        });

        // take permission for Gallery, aka CameraRoll
        const { statusRoll } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
        this.setState({
            cameraRoll: statusRoll
        });
    };





    findNewImage = async () => {
        this._checkPermissions();

        let result = await ImagePicker.launchCameraAsync({
            mediaTypes: "Images",
            allowsEditing: true,
            quality: 1
        });

        console.log("image picked is = result = ", result);

        if (!result.cancelled) {

            console.log("upload image");
            this.setState({
                imageSelected: true,
                imageId: this.uniqueId(),
                uri: result.uri
            });

        } else {

            console.log("cancel");
            this.setState({
                imageSelected: false
            });

        }
    };


Это сообщение об ошибке в Android Studio:

W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 9):
    ReferenceError: Can't find variable: Permissions
    _callee$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141092:62
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19
    tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9
    doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25
    Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14
    callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29
    enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157
    async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69
    _callee@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141087:42
    _callee2$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141135:40
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19
    tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9
    doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25
    Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14
    callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29
    enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157
    async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69
    _callee2@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141131:42
    onPress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141451:39
    touchableHandlePress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:51687:47
    touchableHandlePress@[native code]
    _performSideEffectsForTransition@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50367:36
    _performSideEffectsForTransition@[native code]
    _receiveSignal@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50293:46
    _receiveSignal@[native code]
    touchableHandleResponderRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50172:26
    touchableHandleResponderRelease@[native code]
    invokeGuardedCallbackImpl@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8533:21
    invokeGuardedCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8624:42
    invokeGuardedCallbackAndCatchFirstError@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8628:36
    executeDispatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8822:48
    executeDispatchesInOrder@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8842:26
    executeDispatchesAndRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8937:35
    forEach@[native code]
    forEachAccumulated@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8927:22
    runEventsInBatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9031:27
    runExtractedEventsInBatch@http://10.0.2.2:8081/index.delta?platform=android&dev=
W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 10):
    ReferenceError: Can't find variable: ImagePicker
    _callee2$@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141138:62
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23241:32
    tryCatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23066:23
    invoke@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23142:30
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23172:19
    tryCallTwo@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24367:9
    doResolve@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24531:25
    Promise@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:24390:14
    callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23171:29
    enqueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23176:157
    async@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:23192:69
    _callee2@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141131:42
    onPress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:141451:39
    touchableHandlePress@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:51687:47
    touchableHandlePress@[native code]
    _performSideEffectsForTransition@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50367:36
    _performSideEffectsForTransition@[native code]
    _receiveSignal@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50293:46
    _receiveSignal@[native code]
    touchableHandleResponderRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:50172:26
    touchableHandleResponderRelease@[native code]
    invokeGuardedCallbackImpl@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8533:21
    invokeGuardedCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8624:42
    invokeGuardedCallbackAndCatchFirstError@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8628:36
    executeDispatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8822:48
    executeDispatchesInOrder@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8842:26
    executeDispatchesAndRelease@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8937:35
    forEach@[native code]
    forEachAccumulated@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:8927:22
    runEventsInBatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9031:27
    runExtractedEventsInBatch@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9038:25
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:10005:36
    batchedUpdates$1@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:21211:20
    batchedUpdates@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:9947:37
    _receiveRootNodeIDEvent@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:10004:23
    receiveTouches@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:10034:34
    __callFunction@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2575:49
    http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2332:31
    __guard@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2529:15
    callFunctionReturnFlushedQueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2331:21
    callFunctionReturnFlushedQueue@[native code]

1 Ответ

1 голос
/ 20 июня 2019

Нет модуля для разрешений, импортированных на странице.Добавьте модуль для разрешений на страницу.React-native имеет модули для прав по умолчанию.

См. здесь , чтобы узнать разрешения

пример

import {PermissionsAndroid} from 'react-native';

async function requestCameraPermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        title: 'Cool Photo App Camera Permission',
        message:
          'Cool Photo App needs access to your camera ' +
          'so you can take awesome pictures.',
        buttonNeutral: 'Ask Me Later',
        buttonNegative: 'Cancel',
        buttonPositive: 'OK',
      },
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('You can use the camera');
    } else {
      console.log('Camera permission denied');
    }
  } catch (err) {
    console.warn(err);
  }
}
...