首页 > 解决方案 > 为什么没有出现权限位置提醒?

问题描述

我正在尝试在我的 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 }
        );
      });
}

谢谢

标签: androidreact-nativegeolocationandroid-permissions

解决方案


推荐阅读