mauron85 / cordova-plugin-background-geolocation

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
537 stars 406 forks source link

BackgroundTask works on simulator but not on actual iPhones #26

Closed brudidier closed 8 years ago

brudidier commented 8 years ago

Hi there! The background geolocation works great on Android, and workED great on iOS but since iOS 9.2 it's seems like it's working only on 10-20% of updated iPhones. I was using the original version of the plugin then it stopped working, so I updated with yours but it's not working either.

Basically it works great on the simulator, with any fake phone running iOS 9.2. I press the home button and the backgroundTask starts with a huge amount of "remaining time" and keep posting to the server. BUT when I install the app on an actual iPhone (not a simulator), then I press Home to put the app in background it says : CDVBackgroundGeoLocation stopBackgroundTask (remaining t: 179ms) and then it doesn't log or do anything anymore.

I've reinstalled everything, platform, plugin etc, I use Cordova 3.9 for iOS, my phone is an iPhone 5S with iOS 9.2 and again, it is working perfectly on simulators. The location updates are allowed in the background (plist file) and are allowed on my phone (always checked)... I didn't modify the plugin and it was working great before the update to iOS 9.2...

Am I the only one facing this here? Thanks for the amazing and hard work though! I've seen a couple of issues kind the same but I wanted to start a fresh thread because I've done several tests and didn't want them to be lost. Let me know if I should post it back to other thread.

mauron85 commented 8 years ago

Thank you @brudidier for detailed explanation. I need to take a look on this. However I cannot promise any timeframe now.

mauron85 commented 8 years ago

Looking at cordova-plugin-geolocation-ios9-fix. Especially at commits:

https://github.com/ionberry/cordova-plugin-geolocation-ios9-fix/commit/c64d06b691c50dff32f43f88b69f7874dfc6370b

https://github.com/ionberry/cordova-plugin-geolocation-ios9-fix/commit/a9c21108b3c57165a641b5b006d68282443e7a3f

And another issue on the topic:

https://github.com/apache/cordova-plugin-geolocation/pull/51

Maybe we can inspire from those.

brudidier commented 8 years ago

Thanks for your quick answer mauron85! I did more test with the app and here are the results:

I tried fix 1 without success. (although the geoloc arrow stays on the top of my screen) I tried fix 2 and when I put the app in the background, the arrow goes away. So it's a more "normal" behavior but not what I wanted. I also did more test with your version of the plugin, and in debug mode it seems like it's tracking me sometimes. I get location updates sometimes every 20minutes or so and sometimes less. But definitely not usable. I walked outside and it took the 3 blocks to start updating my position then stopped again. Even while driving it's not really sending a position at a regular interval. Is there maybe a way to remove the stationary feature (if it's the reason)? I need something more consistant. :( Here are my config parameters for iOS : desiredAccuracy: 10, stationaryRadius: 10, distanceFilter: 20, activityType: 'AutomotiveNavigation', debug: true, // <-- enable this hear sounds for background-geolocation life-cycle. stopOnTerminate: false// <-- enable this to clear background location settings when the app terminates

Also, it doesn't show the blue bar at the top even though it's tracking me sometimes. Hope this helps and thanks again! I'm pursuing my tests.

brudidier commented 8 years ago

I actually got it fixed by updating the cordova geolocation plugin + adding the two lines from 3) + removing stationary filter stuff :)

Thanks!

mauron85 commented 8 years ago

Can you share more details. Did you modify this plugin or replaced it with cordova geolocation plugin? Regarding stationary filter, there is statement about it repo, I forked from.

on iOS, background tracking won't be engaged until you travel about 2-3 city blocks, so go for a walk or car-ride (or use the Simulator with Debug->Location->City Drive)

Do you live in a big city with lot a GSM cells, or rather in small? I think size of city, can affect plugin experience greatly.

brudidier commented 8 years ago

Sure Mauron85, sorry about that! I actually just tried with the plugin cordova - geolocation 2.1.0 and it's not working properly. The working version for me was the 1.9 2.1 is not launching the backgroundmode the first time I put the app in the background but only the second time + the blue bar is at the top of the screen saying it's tracking me only the second time two. So its need two switches from foreground to background in order for the plugin to work. With 1.9 it starts perfectly and track my position in the background but the blue bar is not at the top of the screen...(hope Apple will still accept my app with that)

I'm using your plugin and removed the Stationery filter because I need something more precise. I live in San Francisco. I kept the distance filter calculation function though. I also added to your plugin these two lines from this link. https://github.com/apache/cordova-plugin-geolocation/pull/51

I tested on iOS8 and it's properly working too. Hope that's helping!

mahmed-ntd commented 8 years ago

Hi Mauron85,

I have been silent user to this thread and tried to use this sample app but no luck.

I have test this sample app on IOS 6,7 on these platforms it is working fine. but on 8.1 it is working fine 8.2 it is working fine but we don't have accuracy most of time i receive CDVBackgroundGeoLocation locationManager failed: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" but again it is fine on 8.3 we have some variations in speed but we can ignore it. on 9.2 it is working fine simulator but not working fine on original device, it seems it is updating location after every 20 or 15 minutes. if you need i can update my project configurations.

mauron85 commented 8 years ago

@mahmed-ntd thank you for the report. need find some time for this. I would like to rewrite iOS part to swift, so it would more maintainable for me (as I don't know ObjectiveC).

There is already such a project, where native part for ios is in swift

https://github.com/pmwisdom/cordova-background-geolocation-services

mahmed-ntd commented 8 years ago

hi @mauron85 thanks for you reply.

mauron85 commented 8 years ago

Dependency on cordova-plugin-geolocation is just wrong. Don't see any reason, why it is required. I need to audit plugin completely and remove old magic stuff.

EDIT: It's not wrong, it required, because it provides CDVLocation.h and more. But unfortunately latest version is not fixed for iOS9, so I'll define <dependency id="cordova-plugin-geolocation-ios9-fix" /> in plugin.xml instead. Hopefully it will resolve some issues.

mauron85 commented 8 years ago

Hi, can plz try 0.9.2 if it resolve your issue? It's already in npm.

mauron85 commented 8 years ago

Please try new version 0.9.3. Dependency on cordova-plugin-geolocation is gone and many other things. Check CHANGES.md.

mauron85 commented 8 years ago

Closing, when reopen when necessary.