React-native:-位置权限对话框不起作用 [英] React-native:- Location permission dialog is not working

查看:52
本文介绍了React-native:-位置权限对话框不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启用我的设备(android pie)的位置.我已经阅读了 react-native 权限的文档,然后尝试实现它,但每次都说位置权限被拒绝".我什至尝试使用外部库(react-native-permissions)然后它说:-未确定:用户尚未收到权限对话框提示".我也在清单中授予了权限(FINE_LOCATION 和 COARSE_LOCATION).我什至尝试在应用程序权限中手动授予权限,但仍然显示权限被拒绝.如何启用定位.

I want to enable location of my device(android pie). I have read the documentation of Permissions of react-native and then tried to implement it but every time it says "Location permission denied". I even tried to use external library(react-native-permissions) then it says:- "undetermined: User has not yet been prompted with a permission dialog". I have given the permissions(FINE_LOCATION and COARSE_LOCATION) in manifest also. I even tried to give permission manually in app permissions but still it says permission denied. How can i enable location.

代码如下:

async requestLocationPermission() {
try {
  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
    {
      title: "Example App",
      message: "Example App access to your location "
    }
  );
  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    console.log("You can use the location");
    alert("You can use the location");
  } else {
    console.log("location permission denied");
    alert("Location permission denied");
  }
} catch (err) {
  console.warn(err);
}
}

在 componentDidMount 中调用它:

calling it in componentDidMount:

componentDidMount(){
this.requestLocationPermission();
}

推荐答案

应用权限方法后,如果您看到类似;位置权限被拒绝"或者您看不到权限"对话框..然后重置您授予的权限.

After applying permission method if u are seeing msg like " Location permission denied"or you are not able to see the Permission dialog..then reset your granted permissions .

1.如果您使用的是模拟器:为此,请在命令提示符下的当前项目目录路径中运行 cmd:运行:"adb shell pm reset-permissions"

1.If you are using an Emulator:For that run a cmd at your current project directory path in command prompt: run:" adb shell pm reset-permissions"

2.如果您正在使用您的设备,则拒绝所有权限设置.

2.If you are using your device then deny all permissions from setting .

这将重置您所有给定的权限.之后,在我的情况下,我可以看到权限对话框,并且可以自行允许或拒绝权限.

this will reset your all given permission .And After that in my case i am able to see the permission dialog box and able to allow or deny the permissions by own.

这篇关于React-native:-位置权限对话框不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆