【问题标题】:React native: crash while requesting permissionsReact Native:请求权限时崩溃
【发布时间】:2018-12-04 03:16:56
【问题描述】:

我正在按照本教程获取用户在 iOS React Native 应用程序上的位置: https://hackernoon.com/react-native-basics-geolocation-adf3c0d10112

使用此代码获取当前位置:

navigator.geolocation.getCurrentPosition((position) => {
  console.log(position); // TBD
  this.setState({ location: true });
}, (error) => {
  console.log(error); // Handle this
  this.setState({ location: false });
}, {
  enableHighAccuracy: true,
  timeout: 20000,
  maximumAge: 1000,
});

但应用程序在此文件处崩溃:

权限Android.js:

  const shouldShowRationale = await NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(

有错误:

TypeError: Cannot read property shouldShowRequestPermissionRationale of undefined at PermissionsAndroid.Request$

但我什至没有在 Android 上运行 - 我在运行 iOS。

这可能是一个 RN 错误或我是如何使用它的?

【问题讨论】:

  • 你能告诉我你的 RN 的版本吗?
  • 版本为 0.57.5

标签: ios react-native geolocation


【解决方案1】:

只需要先请求权限:

await navigator.geolocation.requestAuthorization();

【讨论】:

    猜你喜欢
    • 2019-01-02
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 2017-03-24
    • 2018-09-15
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    相关资源
    最近更新 更多