pmwisdom/cordova-background-geolocation-services

Http request

Closed this issue · 16 comments

Hi,

Why the call http POST request to my server (backend to save location) is not executing in background?

bgLocationServices.registerForLocationUpdates(function(location) {
$http.post('/locations', location, config).then(successCallback, errorCallback);
}, function(err) {
console.log("Error: Didnt get an update", err);
});

@diegobill If you put a console log in the success callback does it fire?

@pmwisdom , the console log in the success callback does it fired just when the app comes back to foreground, when it come back to foreground all locations captured during background are sended. I need send the location to backend during background immediatly it captured by GPS.

@diegobill Not a lot to go on there. The plugin does this, and has for many projects i've personally been a part of. I'm gonna say its something on your end.

Could be an issue with another plugin or the version of cordova your using.

@pmwisdom , ionic info:

Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 3.13
Node Version: v7.4.0
Xcode version: Not installed

Plugin version: https://github.com/pmwisdom/cordova-background-geolocation-services.git#cf90dcb854a918b1b34c5826f7e01f7fdc1ad885

On iOS the http post works fine, but on Android does not:

bgLocationServices.registerForLocationUpdates(function(location) {
    console.log('FIRED IMMEDIATLY WHEN GPS CAPTURE THE LOCATION IN BOTH STATES FOREGROUND AND BACKGROUND');
    $http.post('/locations', location, config).then(function(){
        console.log('IN FOREGROUND IS FIRED IMMEDIATLY WHEN GPS CAPTURE THE LOCATION, IN BACKGROUND ALL POSITIONS ARE CAPTURE BY GPS BUT ALL SEND JUST WHEN APP COMES BACK TO FOREGROUND')
    }, 
    function(){
    });
}, function(err) {
    console.log("Error: Didnt get an update", err);
});

It is like the plugin mauron85 not setting the options.url (https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting).

+1

same problem here, can't send http request while the app in background mode!

Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.2
ios-deploy version: 1.9.0
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.2.1
Xcode version: Xcode 8.0 Build version 8A218a

Could this be an issue with Ionic? If my callback is coming back immediately, and the ionic http method is not, and you are both using ionic then I'm not sure what I could do to solve this issue.

My plugin doesn't POST at all, so it doesn't user a URL.

What if you put your app in the background after you add this to your code.

setInterval(function() {
 $http.post('/locations', {}, {}).then(function(){
        console.log('IN FOREGROUND IS FIRED IMMEDIATLY WHEN GPS CAPTURE THE LOCATION, IN BACKGROUND ALL POSITIONS ARE CAPTURE BY GPS BUT ALL SEND JUST WHEN APP COMES BACK TO FOREGROUND')
    }, 
    function(){
    });
}, 1000);

Does that fire in the background?

@pmwisdom ,

I did not understand your sugestion. It is that below?

bgLocationServices.registerForLocationUpdates(function(location) {
    setInterval(function() {
        $http.post('/locations', location, config).then(function(){
            console.log('IN FOREGROUND IS FIRED IMMEDIATLY WHEN GPS CAPTURE THE LOCATION, IN BACKGROUND ALL POSITIONS ARE CAPTURE BY GPS BUT ALL SEND JUST WHEN APP COMES BACK TO FOREGROUND')
        }, 
        function(){
        });
    }, 1000);
}, function(err) {
    console.log("Error: Didnt get an update", err);
});

Try the set interval without my plugin at all.

So the setInterval without registerForLocationUpdates.

@diegobill did it work with you?

@AsimNet , I did nota test ter

Did you test?

@pmwisdom and @AsimNet , did not work in background using the setTimeout, the post only work in foreground.

setTimeout works to iOS not to android

@diegobill Looking like it might be a problem with ionic / cdv configuration then? I know ionic uses katzers background plugin. You could try that and see if that works.

@pmwisdom , I use https://github.com/SidharthPHariharan/cordova-HTTP to send request in background so works and use your plugin to get location in background.

Going to mark this is resolved since there is a workaround.