Richou / react-native-android-location-enabler

Display a GoogleMap like android popup to ask for user to enable location services if disabled
MIT License
209 stars 52 forks source link

Promise not working #8

Closed vink1987 closed 6 years ago

vink1987 commented 6 years ago

When the gps is turned off and we open the app, I call promptForEnableLocationIfNeeded method which asks the user to enable location with Ok and Cancel buttons. When user selects Ok or Cancel, the promise doesn't work in react-native code. Please update the code.

Richou commented 6 years ago

I've tried your case and that worked for me as you can see on the gif bellow:

promise-working

The code I used :

export default class App extends Component<{}> {

  componentDidMount = () => {
    this.onLocationEnable();
  }

  onLocationEnable = () => {
    RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
      .then(data => {
        alert(data);
      }).catch(err => {
        alert("Error " + err.message + ", Code : " + err.code);
      });
  }
}
koo27 commented 5 years ago

Actually it's not working for the catch promise. If the user clicks OK, it enters in .then and shows the alert, but if I click on Cancel, nothing happens. Just try to write a console.log inside .catch(err=> {}) and you'll see that nothing shows up. Any idea about this?

gabrielgreghi commented 5 years ago

Eu tive o mesmo problema =( , as vezes, mesmo quando o usuário pressionando no OK, o promisse cai no catch. =(