android - 为什么没有出现权限位置提醒?
问题描述
我正在尝试在我的 react native android 应用程序上显示位置权限警报,但没有出现。
这是我的代码,首先是调用检查权限的函数:
checkPermission = async cb => {
if (Platform.OS === "android") {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "IZI CHECK",
message: translate("access_location_msg")
}
);
console.log("granted:", granted);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
cb();
} else {
alert(translate("location_permission_denied"));
}
console.log("Granted:", granted);
} catch (err) {
console.warn(err);
}
} else {
cb();
}
};
最后,我调用了componentdidmount():
async componentDidMount() {
await this.checkPermission(() => {
navigator.geolocation.getCurrentPosition(
(position)=>{
this.fetchProfileStatus(position);
},
error => {
if (error.code) {
console.log(error)
this.props.navigation.goBack();
}
},
Platform.OS === 'android' ? {} :{enableHighAccuracy: true, timeout: 20000 }
);
});
}
谢谢
解决方案
推荐阅读
- c++ - Nvidia 擎天柱 NvOptimusEnablement
- python - 使用 Django 下载文件
- scala - Scala中的行聚合
- c++ - 为什么结构化绑定依赖于 tuple_element?
- spring-boot - Spring Boot 静态内容在本地工作正常,但当我推送到 VPS 服务器时却不行
- angular - “这个”如何在 _.each 循环中工作?/ 你如何调用 _.each 循环的返回值?
- keras - 如何强制 LSTM 学习单调序列?
- php - 调用未定义的方法 app\models\etc.. Yii2
- ms-access - Microsoft Access - 包括上次修改者
- prometheus-alertmanager - Prometheus Alertmanager 通过 UI 使警报静音不会阻止警报首次出现以触发