ios - React Native:请求权限时崩溃
问题描述
我正在按照本教程获取用户在 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:无法读取 PermissionsAndroid.Request$ 未定义的属性 shouldShowRequestPermissionRationale
但我什至没有在 Android 上运行 - 我在运行 iOS。
这可能是一个 RN 错误还是我如何使用它?
解决方案
只需要先请求权限:
await navigator.geolocation.requestAuthorization();
推荐阅读
- reactjs - 使用 Yarn 2 链接 React 组件时未找到模块错误
- python - 有没有办法比较 Python 中的列表,类似于 excel 中的 vlookup
- reactjs - react/antd中的抽屉在右侧没有打开,就在所有组件的下方
- php - 更新(刷新)PHP 变量而不刷新网站
- c# - CA2235:字段是可序列化类型的成员,但属于不可序列化的 .NET 标准类型
- python - 如何将纯文本列表转换为 python 3 列表
- awk - 检查 GAWK 二进制字符
- .net - 是否可以从 .Net Framework 项目制作全局工具?
- c++ - C++ Hello World 程序中的错误
- android - 线性布局中的浮动操作按钮未显示