Expo App不显示位置许可的弹出窗口

问题描述 投票:0回答:1

在我的博览会应用程序中,我想获取用户的位置,我正在尝试使用与在Expo的官方网站上获取用户位置相同的代码。但是展示应用程序没有显示位置权限的弹出窗口,请参阅下面的代码,

componentWillMount() {
this._getLocationAsync();
}

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status !== 'granted') {
  this.setState({
    errorMessage: 'Permission to access location was denied',
  });
}

// let location = await Location.getCurrentPositionAsync({});
// this.setState({ location });
};

另一方面,如果我将Permissions.LOCATION替换为Permissions.CAMERA,则应用程序会显示弹出窗口以获取权限。

请帮助我无法解决这个问题我正在使用Android设备

android react-native expo
1个回答
1
投票

不推荐使用第一个componentWillMount。尝试使用componentDidMount

其次,您可能已经向app提供了位置权限。如果已提供权限,请检查手机上的设置。如果是,请在设置上进行更改,然后重试。

componentDidMount() {
this._getLocationAsync();
}

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status !== 'granted') {
  this.setState({
    errorMessage: 'Permission to access location was denied',
  });
}

// let location = await Location.getCurrentPositionAsync({});
// this.setState({ location });
};
© www.soinside.com 2019 - 2024. All rights reserved.