1

I am using ionicv1, that uses angularjs,I am using this listener:

I'm adding this listener in a controller

document.addEventListener ("resume", function(){
  getStatusGPS()
}, false);

function getStatusGPS(){
 cordova.plugins.diagnostic.isLocationEnabled(
  function(gps){
     alert(gps)

    if(gps){
     onRequestSuccess();
    }
    else{
      if (ionic.Platform.isIOS()) {
          ionicpopup.generate("Advertencia", "Debes activar la geolocalización desde los ajustes de tu dispositivo para utilizar este servicio",null,"fn_llamarGpsIos",$scope)
      }
      else{
        cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);

      } 
   }
 },function(error){
    console.log(error)
 })

If I put this event of this way, not works for me:

document.addEventListener("resume",getStatusGPS(), false);

when I leave the view I try to eliminate it.

$scope.$on('$destroy', function() {
  document.removeEventListener ("resume", function(){
   getStatusGPS()
  }, false);
})

but when I exit the application and re-enter any controller, the method assigned to it is executed. how can I solve that?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
yavg
  • 2,761
  • 7
  • 45
  • 115
  • I think you have this dilemma because you don't see the difference between a function and a *function call*, which is **not** the same. This would probably work: `document.addEventListener("resume",getStatusGPS, false);` – ippi Jun 12 '18 at 04:37

0 Answers0