question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'requestPermission' of undefined

See original GitHub issue

An error occurs while accessing permissions.

TypeError: Cannot read property 'requestPermission' of undefined

This error is located at:
    in QRCodeScanner (at Scanner.tsx:15)
    in QRScanner (at Login.tsx:36)
    in RCTView (at View.js:45)
    in View (at Login.tsx:33)

What’s happening?

When I add a scanner component to the render.

How can it be reproduced?

import React, { Component } from "react";
import { AppRegistry, Text, TouchableOpacity, Linking } from "react-native";
import QRCodeScanner from "react-native-qrcode-scanner";
import styles from "./Scanner.styles";

class QRScanner extends Component {
  error: any;

  onSuccess = (e: any) => {
    Linking.openURL(e.data).catch(err => (this.error = err));
  };

  render() {
    return (
      <QRCodeScanner
        onRead={this.onSuccess}
        topContent={
          <Text style={styles.centerText}>
            Go to{" "}
            <Text style={styles.textBold}>wikipedia.org/wiki/QR_code</Text> on
            your computer and scan the QR code.
          </Text>
        }
        bottomContent={
          <TouchableOpacity style={styles.buttonTouchable}>
            <Text style={styles.buttonText}>OK. Got it!</Text>
          </TouchableOpacity>
        }
      />
    );
  }
}

AppRegistry.registerComponent("default", () => QRScanner);

export default QRScanner;
// in some component

  public render() {
    return (
      <View style={styles.container}>     
        <QRScanner />       
      </View>
    );
  }

I detected error here on step 1.

// const CAMERA_PERMISSION = "camera";

console.log(1)
Permissions.request(CAMERA_PERMISSION).then(response => {
         console.log(2)
        this.setState({
          isAuthorized: response === PERMISSION_AUTHORIZED,
          isAuthorizationChecked: true
        });
});

If i change "camera" from const CAMERA_PERMISSION = "camera"; on "ios.permission.CAMERA" from CAMERA: "ios.permission.CAMERA"; of react-native-permissions types, I achieve some result.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:12

github_iconTop GitHub Comments

2reactions
dodeca-devcommented, Oct 17, 2019

experiencing this problem too. anyone who solved this issue?

Check this pull request 1a842ef

Works great. Thanks!

1reaction
JuanCamilo0809commented, Nov 3, 2019

experiencing this problem too. anyone who solved this issue?

Check this pull request 1a842ef

But you need:

react-native-permissions 2.0.0 exactly, it is up, not work, only with the 2.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property getPermissionStatus of undefined
I downgraded React Native to 0.52.0 as that's the last react-native-permissions updated their README and I still get the same error. react- ...
Read more >
Notification.requestPermission() - Web APIs - MDN Web Docs
The requestPermission() method of the Notification interface requests permission from the user for the current origin to display notifications.
Read more >
cordova-plugin-health/Lobby - Gitter
I get "Uncaught TypeError: Cannot read property 'isAvailable' of undefined" with I try the "navigator.health.isAvailable(successCallback, errorCallback)" ...
Read more >
Tizen.ppm undefined, tizen object does exist (web app for TV ...
…but it errors out in console: TypeError: Cannot read property 'requestPermission' of undefined as if the ppm property of the tizen object ...
Read more >
react-native-permissions - npm
An unified permissions API for React Native on iOS, Android and Windows. Latest version: 3.6.1, last published: 5 months ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found