Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermissionsAndroid pre Android 23, iOS platform #17438

Closed
DanGDroid opened this issue Jan 4, 2018 · 1 comment
Closed

PermissionsAndroid pre Android 23, iOS platform #17438

DanGDroid opened this issue Jan 4, 2018 · 1 comment
Labels
Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@DanGDroid
Copy link

Is this a bug report?

yes

Have you read the Contributing Guidelines?

yes

Environment

react-native: 0.45.1

Steps to Reproduce

use the react native api example for handling Android run time permissions,
https://facebook.github.io/react-native/docs/permissionsandroid.html#checkpermission

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.'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera")
    } else {
      console.log("Camera permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}

run the example method.

Expected Behavior

  1. run on Android >= 23. === will prompt the user for permission.
  2. run on Android < 23. === react-native will handle the cases and will print "You can use the camera" as if no PermissionsAndroid was used.
  3. run on iOS. === native ios permission behaviour as if PermissionsAndroid was used.

Actual Behavior

  1. result as expected => prints "You can use the camera".
  2. result as if no permission granted - request returns true, not string 'granted'.
    so result is "Camera permission denied".
  3. throws an exception
index.ios.bundle:47286 TypeError: Cannot read property 'shouldShowRequestPermissionRationale' of undefined
    at PermissionsAndroid.request$ (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:53781:80)
    at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)
    at Generator.invoke [as _invoke] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22746:22)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22583:21)
    at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22558:40)
    at invoke (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22616:20)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:22646:11
    at tryCallTwo (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:11879:5)
    at doResolve (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:12018:13)
    at new Promise (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:11900:3)

and no print at all.

i think all these cases should be handled by the api or specified in the example code.

the way to get it working in all three case is by modifying the example code to this:

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.'
      }
    )
    if (Platform.OS !== 'android' || granted === true || granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera")
    } else {
      console.log("Camera permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}
@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants