Closed turkialarjani closed 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.
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.
I travel about 40 Km and nothing happened.
Logs please.
The plugin stores 3 days worth of logs by default. Fetch them with getLog
Yes, and I use cellular data.
post it to a gist: https://gist.github.com/
After i terminate the app Xcode display this:
2017-01-21 - TSBackgroundFetch onAppTerminate 🔵-[TSLocationManager onAppTerminate] stopOnTerminate? 0 ⋯-[TSDBLogger db_save] Log committed
Is there something you don't understand about getLog
Yes how to post getlog to gist.
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.
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.
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
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();
}
}
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.
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.
The js error screenshot: was that the web console of the app running on your device or the browser?
browser
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?
It's working now thank you.
Another question, how I can post the location using HTTP request every movement?
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
Plugin version OS version: Device manufacturer / model:
Your Environment
cordova -v
): 6.4.0cordova platform ls
):ios 4.3.1 -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