transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

Location not working when i terminate the App #259

Closed turkialarjani closed 7 years ago

turkialarjani commented 7 years ago

Your Environment

bgGeo.configure({
        // Geolocation config
        desiredAccuracy: 0,
        distanceFilter: 10,
        stationaryRadius: 50,
        locationUpdateInterval: 1000,
        fastestLocationUpdateInterval: 5000,

        // Activity Recognition config
        activityType: 'AutomotiveNavigation',
        activityRecognitionInterval: 5000,
        stopTimeout: 5,

        // Application config
        debug: true,
        stopOnTerminate: false,
        startOnBoot: true,

        // HTTP / SQLite config
        url: server_url+'users/location/',
        method: 'POST',
        autoSync: true,
        maxDaysToPersist: 1,
        }, function(state) {
        // This callback is executed when the plugin is ready to use.
        console.log('BackgroundGeolocation ready: ', state);
        if (!state.enabled) {
            bgGeo.start();
        }
    });

Expected Behavior

-Send the location to server when the app is terminated.

Actual Behavior

-No thing happen when app terminated. -The plugin stop when the app terminated.

Debug logs

christocracy commented 7 years ago

After app termination with stopOnTerminate: false, the plugin must exit the "stationary-geofence" before iOS will reboot the app. Typically, you must move 200 meters before this occurs.

christocracy commented 7 years ago

You can watch a demo of stopOnTerminate: false in this video. On iOS, stopOnTerminate: false does not prevent the app from terminating -- it just ensures your app will reboot in the backgrond when the device is detected to be moving (ie: when the device exits the "stationary geofence" around the last-known location.

turkialarjani commented 7 years ago

I travel about 40 Km and nothing happened.

christocracy commented 7 years ago

Logs please.

christocracy commented 7 years ago

The plugin stores 3 days worth of logs by default. Fetch them with getLog

turkialarjani commented 7 years ago

Yes, and I use cellular data.

christocracy commented 7 years ago

post it to a gist: https://gist.github.com/

turkialarjani commented 7 years ago

After i terminate the app Xcode display this:

2017-01-21 - TSBackgroundFetch onAppTerminate 🔵-[TSLocationManager onAppTerminate] stopOnTerminate? 0 ⋯-[TSDBLogger db_save] Log committed

christocracy commented 7 years ago

Is there something you don't understand about getLog

turkialarjani commented 7 years ago

Yes how to post getlog to gist.

christocracy commented 7 years ago

Open the Safari Javascript Console and execute the method directly in the console:

>bg = window.BackgroundGeolocation;
>bg.getLog(function(log) { console.log(log); });

Copy / paste to Gist.

turkialarjani commented 7 years ago

screen shot 1438-04-23 at 11 34 26 pm

christocracy commented 7 years ago

Well, well. You have just learned the importance of monitoring the web console during mobile development.

You have a JavaScript error in your code. The plugin not responsible for syntax errors in your code.

This is most certainly the cause of your problem.

christocracy commented 7 years ago

When you see me using the var bgGeo in example code it's assumed you've first declared that variable in your code, eg:

var bgGeo = window.BackgroundGeolocation;

Read the README: https://github.com/transistorsoft/cordova-background-geolocation-lt#using-the-plugin

turkialarjani commented 7 years ago

I already use it :

var bgGeo = window.BackgroundGeolocation;

//This callback will be executed every time a geolocation is recorded in the background.
var callbackFn = function(location, taskId) {
    var coords = location.coords;
     lat    = coords.latitude;
     lng    = coords.longitude;
    console.log('- Location: ', JSON.stringify(location));
    // Must signal completion of your callbackFn.
    bgGeo.finish(taskId);
};

// This callback will be executed if a location-error occurs.  Eg: this will be called if user disables location-services.
var failureFn = function(errorCode) {
    console.warn('- BackgroundGeoLocation error: ', errorCode);
}

// Listen to location events & errors.
bgGeo.on('location', callbackFn, failureFn);

// Fired whenever state changes from moving->stationary or vice-versa.
bgGeo.on('motionchange', function(isMoving) {
  console.log('- onMotionChange: ', isMoving);
});

// BackgroundGeoLocation is highly configurable.
bgGeo.configure({
    // Geolocation config
    desiredAccuracy: 0,
    distanceFilter: 10,
    stationaryRadius: 50,
    locationUpdateInterval: 1000,
    fastestLocationUpdateInterval: 5000,

    // Activity Recognition config
    activityType: 'AutomotiveNavigation',
    activityRecognitionInterval: 5000,
    stopTimeout: 5,

    // Application config
    debug: true,
    stopOnTerminate: false,
    startOnBoot: true,

    // HTTP / SQLite config
    url: server_url+'users/location/',
    method: 'POST',
    autoSync: true,
    maxDaysToPersist: 1,
    headers: {
        'token': '4kkuKkpSZuJ1efExodtWSCbcn7fDM7MN'
    },
    params: {
        actualLat: lat,
        actualLng: lng
    }
}, function(state) {
    // This callback is executed when the plugin is ready to use.
    console.log('BackgroundGeolocation ready: ', state);
    if (!state.enabled) {
        bgGeo.start();
    }
});

// The plugin is typically toggled with some button on your UI.
function onToggleEnabled(value) {
    if (value) {
        bgGeo.start();
    } else {
        bgGeo.stop();
    }
}
christocracy commented 7 years ago

And are you accessing the plugin in the deviceready event?

You're not trying to access the plugin by booting your app in the browser, are you? Cordova plugins are not available in the browser.

turkialarjani commented 7 years ago

Yes, every thing in plugin work fine when i build it in my phone using Xcode but when i terminate the app it doesn't work. Note: my app is hybrid - jQuery Mobile.

christocracy commented 7 years ago

The js error screenshot: was that the web console of the app running on your device or the browser?

turkialarjani commented 7 years ago

browser

christocracy commented 7 years ago

How do you expect to debug an iOS issue in the browser?

The plugin doesn't exist in the browser.

Boot the web console of the device. Are you not aware you can do this?

turkialarjani commented 7 years ago

It's working now thank you.

turkialarjani commented 7 years ago

Another question, how I can post the location using HTTP request every movement?

christocracy commented 7 years ago

Yes https://github.com/transistorsoft/cordova-background-geolocation-lt/tree/master/docs#http--persistence-options

tarunsharpdeveloper commented 4 years ago

in android app is not tracking location when exit , i used this to start in background, BackgroundGeolocation.start();

even i also check in your hello-world example

christocracy commented 4 years ago

Plugin version OS version: Device manufacturer / model: