webyonet / react-native-android-location-services-dialog-box

React Native Android Location Services Dialog Box
MIT License
182 stars 50 forks source link

How to know when GPS was enabled? #21

Closed denebchorny closed 7 years ago

denebchorny commented 7 years ago

I want to know how to check if the gps was enabled by the user after the displayed dialog or before.

I mean, using you method there could be 2 stages:

LocationServicesDialogBox.checkLocationServicesIsEnabled({
            message: "",
            cancel: "",
            ok: ""
        })  
        .then(function (success) {})
        .catch((error) => {  });

1) If the GPS is enabled (before showing the dialog) calling your method will return success 2) If the GPS is disabled (before showing the dialog) calling your method will return succes if and only if the user enable the GPS in the prompted interface

Why I need this? I have a button. If it is pressed and the GPS is disabled I show a dialog, and if the user enable the GPS in the prompted interface I dont want to continue the process instead the user has to click the button again.

In the case the GPS is enabled then there is no any dialog to show.

I don't know if you understand what I'm trying to say.

PD: I don't know if this article could be useful. In my case I don't know how to do what it says https://stackoverflow.com/questions/41795968/react-native-check-and-promp-user-to-enable-network-gps/42002015#42002015

How can I achieve this?

webyonet commented 7 years ago

At the moment this feature is not supported. I can add this feature soon. (After and before client interaction)

Thanks.

webyonet commented 7 years ago

v2.0.0 fixed

Sidibedev commented 6 years ago

I got a error : undefined is not a object (evaluating '_reactNativeAndroidLocationServicesDialogBox2.defauly.checkLocationServicesEnabled') Help please

robado commented 6 years ago

Getting the same error as @Sidibedev . My code looks like `import LocationServicesDialogBox from "react-native-android-location-services-dialog-box";

LocationServicesDialogBox.checkLocationServicesIsEnabled({ message: "Use Location ?", ok: "YES", cancel: "NO" }).then(function(success) { console.log(success); // success => "enabled" }).catch((error) => { console.log(error.message); // error.message => "disabled" });`

Is there something like that this isn't working with not ejected apps?

vohoangankhanh commented 6 years ago

TypeError: undefined is not an object (evaluating '_reactNativeAndroidLocationServicesDialogBox2.default.checkLocationServicesIsEnabled') . I have the same error too

webyonet commented 6 years ago

RN and android version ?

vohoangankhanh commented 6 years ago

yes, react native 0.55.3 and running on Android device 6.0

"dependencies": {
        "expo": "^27.0.1",
        "react": "^16.3.1",
        "react-addons-update": "^15.6.2",
        "react-native": "0.55.3",
        "react-native-android-location-services-dialog-box": "^2.4.4",
        "react-native-keyboard-spacer": "^0.4.1",
        "react-native-permissions": "^1.1.1",
        "react-navigation": "^1.5.11",
        "react-redux": "^5.0.7",
        "redux": "^4.0.0",
        "redux-thunk": "^2.2.0"
    }
"expo": {
        "sdkVersion": "27.0.0"
    },
stinkymonkeyph commented 6 years ago

had there been any fix for this yet ?

arbabi2010 commented 6 years ago

TypeError: undefined is not an object (evaluating '_reactNativeAndroidLocationServicesDialogBox2.default.checkLocationServicesIsEnabled') . I have the same error too

I've used this package before in react native 0.46 with version 2.2.1 and work fine but now with react natve 0.51 and this package version 2.5 i get this error

webyonet commented 6 years ago

-- restart your PC or MAC (for background process) -- uninstall your app on mobile device

folow the steps below at the terminal step by step :

1) react-native unlink react-native-android-location-services-dialog-box
2) npm uninstall react-native-android-location-services-dialog-box
3) npm install react-native-android-location-services-dialog-box --save
4) react-native link react-native-android-location-services-dialog-box
5) react-native run-android
isaaclem commented 5 years ago

@webyonet : Very nice package! Any plan to implement for iOS?

webyonet commented 5 years ago

Hi @isaaclem this feature is native for ios

arbabi2010 commented 4 years ago

I Fix it, I change compileOnly to Compile and it work properly