|
|
@@ -7,8 +7,51 @@ import { StyleSheet, View } from 'react-native';
|
|
|
import { check, openSettings, PERMISSIONS, request, RESULTS } from 'react-native-permissions';
|
|
|
import Button from '../../../components/Button';
|
|
|
import TextView from '../../../components/TextView';
|
|
|
+import LocationEnabler from 'react-native-location-enabler';
|
|
|
|
|
|
//global.hasPermission = false;
|
|
|
+const {
|
|
|
+ PRIORITIES: { HIGH_ACCURACY },
|
|
|
+ addListener,
|
|
|
+ checkSettings,
|
|
|
+ requestResolutionSettings
|
|
|
+} = LocationEnabler;
|
|
|
+
|
|
|
+class LocationListener {
|
|
|
+ constructor() {
|
|
|
+ this.listener = undefined;
|
|
|
+ this.config = {
|
|
|
+ priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
|
|
|
+ alwaysShow: false, // default false
|
|
|
+ needBle: false // default false
|
|
|
+ };
|
|
|
+ this.status = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ addListener() {
|
|
|
+ this.listener = addListener(({ locationEnabled }) => {
|
|
|
+ if (!locationEnabled) {
|
|
|
+ console.log("status: " + this.status + "," + locationEnabled);
|
|
|
+ if (this.status != locationEnabled) {
|
|
|
+ this.status = locationEnabled;
|
|
|
+ requestResolutionSettings(this.config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ removeListener() {
|
|
|
+ if (this.listener) {
|
|
|
+ this.listener.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ check() {
|
|
|
+ this.status = undefined;
|
|
|
+ checkSettings(this.config)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 检查是否有定位权限
|
|
|
@@ -150,5 +193,6 @@ const styles = StyleSheet.create({
|
|
|
export default {
|
|
|
VIEW: LocationPermission,
|
|
|
checkPermission: checkPermission,
|
|
|
- requestPermission: getPermission
|
|
|
+ requestPermission: getPermission,
|
|
|
+ LocationListener: LocationListener
|
|
|
}
|