-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing locations while the app is in the background #80
Comments
I test this plugin using the example app. If you can reproduce your problem using the example app, then there is a problem with the plugin. To debug problems, I litter the code with print statements and then walk around with my phone plugged into my laptop, and a debugger open. The relevant Android code is in BackgroundGeolocation.java and BackgroundGeolocationService.java. |
Thanks for the super fast response! |
Was your phone locked the entire time? Or just for the short time when it stopped recording? You could modify the plugin to write to a log file on disk, that would be much simpler than writing to a database. You could also modify your application to write to a separate log file. Then, the log files can be compared. |
Ah, yes, disk log file is a lot simpler. |
Would you be interested in a PR which writes some app logs to file and allowing to retrieve the file's content from capacitor js code? |
No, sorry. I intend to keep this plugin as simple as possible. But if you find a way to reliably reproduce the problem I will take a look at it. Keep in mind that GPS is not super reliable - satellites are constantly moving, and the device must work to maintain a fix. We have found that in certain places, at certain times, with certain devices, or even in certain cars (interference?) GPS can be extremely flakey. |
Actually, I'm thinking that this might be a good idea. What about something like this? BackgroundGeolocation.addWatcher(
{
...
// In addition to being delivered to the callback, locations can be
// appended to a file. Locations that have been written to disk are
// more likely to survive a crash. Each location is JSON encoded and
// appended to the file as a single line.
// The "file" option, if specified, is a string containing the URI to a
// writable file. The file is created if it does not exist.
file: "file:///path/to/my_locations.txt"
... |
This is a very simple and elegant solution! I like it. |
It is up to the app to delete the file, if it wants to, and it can do any at any time. If at any time the file does not exist and the plugin wants to write a location to it, then a new file will first be created. Why would there be file corruption? |
I see. I don't know, if you delete while writing? |
If the file is deleted partway through a write (which might be possible if each happen on a different thread) then:
We can handle the exception, of course, but I think we can leave it up to the consumer of the file to ignore any lines that can not be parsed as JSON. In practice, I think there will be minimal opportunity for corruption. |
I see, you're probably right. I'm in 😄 |
Would you like to build it? |
Whatever works for you. I can give it a go. |
Yes please. |
I have an initial POC that works on my android device. |
I think it would be a useful feature on iOS because the WKWebView is so prone to crashing. I imagine I think the file should contain the same format that is delivered to the callback, so yes, JSON please. There are no tests, but you could modify the example app to make use of this feature. |
Ok, thanks for the info! |
I had the same problem today twice when I recorded a route. The other option might be to use the GPS provider and not the fused location which I was using in the past (which is more noisy but basically what you want to have here - get the data from the GPS): Unfortunately, I didn't have the log PR in my app so I have no more info besides the observation I wrote above. |
I did see similar problems on iOS when taking photos during tracking. So yes, the geo app is in background, but taking a photo shifts the problem rate to about 80% of the tests. Andreas |
i remarks that GPS does not work when the device has no network. Perhaps it is your case. Easily to reproduce, enable/disable data mobile. i opened a ticket #98 |
I'm not sure this is the cause in my case, but reception shouldn't matter for in theory, might be another issue... |
Facing the same issue on android. |
Has anyone encountered the problem where the app ceases to track geolocation while recording a video through the camera, especially when the app is running in the background? Issue is on android, with iOS works fine |
Describe the bug
I'm using this plugin in my app and it generally works great. Thanks for all the effort you put into it!
Having said that, I noticed in my last recording that there was a place where there were no locations updates for 6 minutes when the app was in the background and after that the GPS seems to trying to reposition itself as the accuracy went down from 120 meters to around 10 in a few seconds.
This can be seen in the following image (I was walking on the blue trail):
I can share the recoding of this session or the log file my app collected if needed.
My question/request is to understand how to better debug these kind of glitches to better understand what went wrong in this case - was the service killed/stopped/paused? the GPS from the phone stopped sending signals? Capacitor stopped receiving messages? etc...
In some cases the OS kills the app, but it doesn't look like it in this case as the app's log doesn't show boot-up messages.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Get locations updates while in the background
Screenshots
See above
Smartphone (please complete the following information):
Additional context
I think it might prove beneficial to store some logging information in the native code and allow fetching this info when required for better debugging? IDK, any insight and thought will be helpful.
If you think there's something I can push forward in terms of PR please let me know.
This plugin is a core capability of my app and I'm willing to invest the time needed to improve this plugin to better support my needs.
The text was updated successfully, but these errors were encountered: