我正在使用软件包react-native-android-location-services-dialog-box
。因此,如果GPS已启用,我将返回this.setState({locationEnabled: true})
,然后导航到我的下一个屏幕,即AuthScreen
,那么我的应用程序应该如何运行。否则,如果GPS在应用启动之前被禁用,它将显示启用GPS的模式,然后导航到AuthScreen
。
我的问题是,在应用启动GPS已启用或禁用的应用程序启动之前,模态仍显示已启用GPS(即使已启用),然后我希望导航到AuthScreen
,因为GPS已经已启用但没有。即使启用或禁用GPS,它也会将“禁用”返回到我的控制台日志。该程序包在success => {alreadyEnabled: false, enabled: true, status: "enabled"}
语句中返回此then
。如何使用它使我的应用程序完美运行?
这是一件奇怪的事。昨天,我的应用程序没有这种行为或流程。昨天我没有更改任何代码,今天我打开我的应用程序,现在我的应用程序的行为如下。请帮我谢谢你!
以下是网址:https://github.com/webyonet/react-native-android-location-services-dialog-box
这是我的代码:
enableLocation = () => {
LocationServicesDialogBox.checkLocationServicesIsEnabled({
message: "<h2 style='color: #0af13e'>Use Location ?</h2>This app wants to change your device settings:<br/><br/>Use GPS, Wi-Fi, and cell network for location<br/><br/><a href='#'>Learn more</a>",
ok: "YES",
cancel: "NO",
enableHighAccuracy: true, // true => GPS AND NETWORK PROVIDER, false => GPS OR NETWORK PROVIDER
showDialog: true, // false => Opens the Location access page directly
openLocationServices: true, // false => Directly catch method is called if location services are turned off
preventOutSideTouch: false, // true => To prevent the location services window from closing when it is clicked outside
preventBackClick: false, // true => To prevent the location services popup from closing when it is clicked back button
providerListener: false // true ==> Trigger locationProviderStatusChange listener when the location state changes
}).then((success) => {
this.setState({
locationEnabled: true
})
}).catch((error) => {
console.log(error.message);
// alert(error.message);
});
};
render() {
if(!this.state.locationEnabled) {
return (
<View style={styles.container}>
</View>
)
} else {
return <AuthScreen/>
}
}