Closed Gurjit-ONEBCG closed 5 years ago
There is, of course, a consequence to using βWhenInUseβ, and this is that most iOS apis that the plugin relies upon, including Geofencing and the SLC (significant location changes) apis, no longer work in the background.
With WhenInUse, the user must manually engage tracking while the app is in foreground via your UI (eg a button that executes changePace(true)
).
Have you read the docs for this option?
You may listen to onProviderChange event to learn if user selects this mode, and warn them against it.
Geofencing
Thanks Chris for you reply.
What I understood is that 1) the location provider was changed after calling start method in my case. 2) I should call the changepace whenever app comes foreground from background 3) Agreed, onProviderChange could be helpful to log user activities with location setting
Yes I had read changepace option and I always call chagepace(true) immediate after calling start method of plugin to engage location tracker immediately
BackgroundGeolocation.start(state => { BackgroundGeolocation.changePace(true); }, error => { });
In my requirement I can not force user to choose 'always' permission. So in case app is not terminated location should log with 'whenInUse' permission as well.
So in case app is not terminated location should log with 'whenInUse' permission as well.
Only if you've executed changePace(true)
while in the foreground.
Imagine a "Jogging app" authorized for "WhenInUse". The user clicks a [Start Workout]
button, which executes changePace(true)
. When app goes to background, iOS renders a "Blue Bar" reading "Some App is using your location". The plugin is alive in the background until stopTimeout
expires, when the plugin will turn off location-services. The plugin cannot automatically trigger location services back on while in the background.
stopOnTerminate: false
/ startOnBoot: true
cannot work with WhenInUse
.
in will turn off location-service
So my problem will be fixed. If I call changepace(true) when 1) app goes in stationary position (using onMotionChange event to detect stationary state) 2) when app goes in foreground ( platform resume event)
Please suggest if it will work
Try it, but if you attempt to keep location-services on all the time (24h / day) with WhenInUse
, you're going to fail.
Try it, but if you attempt to keep location-services on all the time (24h / day) with
WhenInUse
, you're going to fail.
Agreed, but my only target is to get location when the app is opened. Thanks for your help. I will share results after performing your suggestion
but my only target is to get location when the app is opened.
What's wrong with using #getCurrentPosition
for that?
but my only target is to get location when the app is opened.
What's wrong with using
#getCurrentPosition
for that?
-In my requirement I need to draw route from user starting position to destination or where user ends the service. -Our client strictly asked to not force user for 'always' permission( But it will be user's wish to choose either 'always' or 'whenInUse' -If I use getcurrentPosition then users will not take advantage who would have set 'always' permission.
One more question please, What max value I can set for stopTimeout (in case iOS)
What max value I can set for stopTimeout (in case iOS)
Infinity.
What max value I can set for stopTimeout (in case iOS)
Infinity.
I think this would be best solution, because I don't need to care about user device's battery
Background service stopped after some time
This is my config
debug: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
useSignificantChangesOnly: false,
maxDaysToPersist: 14,
stopOnTerminate: false,
startOnBoot: true,
foregroundService: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
autoSync: true,
batchSync: true,
maxBatchSize: 20,
heartbeatInterval: 5,
preventSuspend: true,
disableElasticity: true,
distanceFilter: 10,
stopTimeout = 600;
locationAuthorizationRequest = "Any";
I have set stopTimeout =600
I set changepace(true) in the foreground and when app goes in stationary state
BackgroundGeolocation.onMotionChange((event) => { if (!event.isMoving) { BackgroundGeolocation.changePace(true); console.log('- in stationary'); } });.
But locations not logged between 16:11 - 16.21
I have also tested sample app in advance mode with 'whenInUse' and clicked on play button(buttom right side) to change pace in foreground. After some time blue notification bar stopped blinking at the top of screen (in app background)
I have used Runtastic app which ask location permission for 'WhenInUse' only and that works perfectly
Even apple doc says
When-in-use authorization. Your app can use most services but cannot use services that automatically relaunch the app. Your app must always start services while running in the foreground. If you enable the background location capability for your app, a suspended app will wake in the background to handle location events. However, if your app is not running, it will not be launched.
Thanks Chris, for your reply. So with this I don't need stoptimeout property. It will bypass Significant-change location service of Apple
I will share the results asap.
So with this I don't need stoptimeout property.
Not if you configure pausesLocationUpdatesAutomatically: false
, as well.
Be careful with pausesLocationUpdatesAutomatically: false
. If you set that true
, location-services will NEVER turn off, ever. It's also a tri-state parameter:
false
: location-services will never turn off once turned on with changePace(true)
.true
: stopTimeout
is ignored. iOS will automatically turn off location-services exactly 20 minutes after device is detected to be stationary.null
: Enable plugin's stopTimeout
mechanism.So with this I don't need stoptimeout property.
Not if you configure
pausesLocationUpdatesAutomatically: false
, as well.Be careful with
pausesLocationUpdatesAutomatically: false
. If you set thattrue
, location-services will NEVER turn off, ever. It's also a tri-state parameter:
false
: location-services will never turn off once turned on withchangePace(true)
.true
:stopTimeout
is ignored. iOS will automatically turn off location-services exactly 20 minutes after device is detected to be stationary.null
: Enable plugin'sstopTimeout
mechanism.
Thanks Chris, What I understood is that location service will never off until I call the stop method with following settings.
' disableStopDetection: true, pausesLocationUpdatesAutomatically: false'
What I understood is that location service will never off until I call the stop method
Correct. #stop
or changePace(false)
.
Hi @christocracy I tested it But location services OFF notification appeared when I stopped for around 20 mins
Service stopped around 19:51
seems stopdetection didn't disabled completely even with following settings. disableStopDetection: true, pausesLocationUpdatesAutomatically: false'
Do the same test with Always
authorization.
Do the same test with
Always
authorization.
Everything was working fine with 'Always'. (With 'Always' location service will be off and ON automatically by detecting significant motion change')
But I want my application work with 'WhenInUse' like 'Runtastic' app. Assume I am building a fitness app and I want keep tracking until user click stop button
Do the same test with Always
and pausesLocationUpdatesAutomatically: false
. Let me know if you see this in the logs:
2019-05-02 19:41:17.147 π΅-[TSLocationManager locationManagerDidPauseLocationUpdates:] Paused location-updates
Do the same test with
Always
andpausesLocationUpdatesAutomatically: false
. Let me know if you see this in the logs:2019-05-02 19:41:17.147 π΅-[TSLocationManager locationManagerDidPauseLocationUpdates:] Paused location-updates
Sure, I will test and will share the data. Thanks
Did the same test with Always and pausesLocationUpdatesAutomatically: false
Sorry, uploading the zip file of logs , so that you can see all the information (its only of single test) background-geolocation (1).log.gz
I think there's a bug in the iOS library with pausesLocationUpdatesAutomatically
.
Try this:
BackgroundGeolocation.ready({
reset: true,
disableStopDetection: true,
pausesLocationUpdatesAutomatically: true,
.
. <all your other config>
.
}).then(async (state) => {
await BackgroundGeolocation.setConfig({
pausesLocationUpdatesAutomatically: false
});
await BackgroundGeolocation.start();
BackgroundGeolocation.changePace(true);
});
Actually, that won't work. Thinking....
Ok, try that.
Ok, try that.
Thanks Chris, for your valuable response. Okay I will try that, and will try to bring results during weekend
Are you using Typescript in your project?
Are you using Typescript in your project?
Yes IONIC 3 , Angular 5 with type script
Ok, try that.
Thanks Chris, It worked. And I don't see 'Paused location-updates' log. background-geolocation.log.gz
If its a bug, are you planning any release for its fixes.
If its a bug, are you planning any release for its fixes.
Of course I am. I can't tell you when.
If its a bug, are you planning any release for its fixes.
Of course I am. I can't tell you when.
Cool! Thanks for your support.
After changing location authorization permission from 'always' to 'whenInUse', plugin din't log locations.(Please check steps to reproduce)
cordova -v
):7Expected Behavior
Plugin should keep working when app is not terminated
Actual Behavior
Plugin stopped tracking locations
Steps to Reproduce
1.Change location authorization permission from 'always' to 'whenInUse' 2.Call the start method 3.Put app in background and traveled around 25 miles 4.Call the stop method
Debug logs
I expect locations between 18:51 - 19:51