【发布时间】:2019-11-08 08:49:40
【问题描述】:
我正在开发 React Native 应用程序。如果用户从一个地方移动/导航到另一个地方,我必须在那里获取多个用户位置。这工作正常,但是,如果用户在一段时间后禁用位置权限,比如用户进入设置禁用权限,我必须显示一些按钮,如启用位置,然后再次显示一旦用户点击该按钮,它应该要求请求位置权限。
但是,如果用户第一次授予权限,并且稍后如果他禁用权限,则请求权限的弹出窗口不会在点击按钮时在 Android 中显示弹出窗口。
我正在使用以下库来获取用户位置详细信息。
import Geolocation from 'react-native-geolocation-service';
// button on click method following
enableLocationHandler = () => {
if (Platform.OS === 'android') {
this.requestLocationPermissions();
} else {
Linking.openURL('app-settings:');
this.getLatitudeLongitude();
}
}
requestLocationPermissions = async () => {
if (Platform.OS === 'android') {
this.getLatitudeLongitude();
} else {
Geolocation.requestAuthorization();
this.getLatitudeLongitude();
}
}
getLatitudeLongitude() {
Geolocation.getCurrentPosition((position) => {
const initialPosition = JSON.stringify(position);
},
(error) => {
if (error.code === 1) {
this.setState({ errorMessage: 'Location permission is denied', isLoading: false });
Geolocation.clearWatch(this.watchID);
}
},
{ enableHighAccuracy: true, distanceFilter: 100, timeout: 20000, maximumAge: 1000 }
);
this.watchID = Geolocation.watchPosition((position) => {
// this.showLoader();
// console.log('position', position);
});
}
有什么建议吗?
【问题讨论】:
-
如果Android和iOS一样,那么权限请求只显示一次。如果用户更改了设备设置中的权限,那么他们必须将它们更改回相同的位置。您所能做的就是显示一个警报,要求用户重新进入设置以启用位置权限
标签: javascript android ios react-native geolocation