Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Pause metrics-collection when app is suspended #2120

Closed
wants to merge 1 commit into from
Closed

Pause metrics-collection when app is suspended #2120

wants to merge 1 commit into from

Conversation

christocracy
Copy link

Pause metrics-collection when app is suspended otherwise MGLMapboxEvents continues to run its locationManager. Since Mapbox only requests NSLocationWhenInUse authorization, if another module (like mine, for instance) requests NSLocationAlwaysUsageDescription authorization, and enables the location in Background Modes:

MGLMapboxEvents' locationManager will continue updating-location, even when the app is suspended preventing iOS from suspending the app.

This puts a huge drain on the battery, of course, not only since the location-manager is running but because the app is prevented from suspending.

…nts continues to run its locationManager. Since Mapbox only requests WhenInUse authorization, if another module requests AlwaysUsage authorization, MGLMapboxEvents' locationManager will continue updating-location PREVENTING iOS FROM SUSPENDING THE APP. This puts a huge drain on the battery, of course.
@incanus incanus added iOS Mapbox Maps SDK for iOS telemetry Integration with Mapbox Telemetry libraries labels Sep 16, 2015
@incanus
Copy link
Contributor

incanus commented Sep 16, 2015

Yes, this is correct @christocracy. If on the free plan, the trade is background location data collection. We have optimized things to be very conservative about the accuracy levels, etc. involved in this collection, so as to only obtain the highest resolution already otherwise collected on the system.

"Preventing iOS from suspending the app" sounds worse than it is, since GL resources, etc. will still be jettisoned when the app is backgrounded.

"Huge drain on the battery" is subjective; yes, it is relatively more than no drain on the battery, but should not be huge. You can read more about this at https://www.mapbox.com/blog/optimizing-battery-ios/

Lastly, your PR does not ever call +[MGLMapboxEvents resumeMetricsCollection] upon wake, so it effectively pauses metrics collection forever on first app backgrounding.

@christocracy
Copy link
Author

I have over 2 years experience developing a sophisticated cross-platform location-manager library which is designed to constantly track a device while running in the background.

Guess what happens when an app enables the UIBackgroundMode of location and requests requestAlwaysAuthorization? While my library does its job in detecting the device is stopped, executing locationManager.stopUpdatingLocation and switching to locationManager.startMonitoringSignificantChanges, the MapBox CLLocationManager instance will keep updating its location even in the background, preventing the app from sleeping and killing the battery in a few hours.

Mapbox must not keep its locationManager running in the background.

@christocracy
Copy link
Author

It's frankly irresonsible, naïve and neglectful to the community for mapbox-gl-native to not take better care in ensuring its CLocationManager can be subordinated to another library with more built-in intelligence upon the movement-state of the device, allowing it to express its desire to allow iOS to suspend the app while running in background.

@christocracy
Copy link
Author

In fact, this kind of behavior could certainly be grounds for Apple declining an otherwise well-behaved application.

@christocracy
Copy link
Author

Furthermore, I mean no offence to you personally, but the information in this URL, is simply laughable. I'm sorry to be so harsh.

https://www.mapbox.com/blog/optimizing-battery-ios/

@christocracy
Copy link
Author

Further-furthermore (last one): How can Optimizing Battery for iOS be taken seriously when it's found using the old deprecated iOS6-era didUpdateToLocation:fromLocation delegate-method?

@aphillipo
Copy link

Hey guys, seems to be like this could be wasting battery? Is there a way to fix the pull request so that it can be merged? Seems like the guy who wrote the library on background geo probably knows a bit about it's battery use!

@christocracy
Copy link
Author

I know everything there is to know about battery consumption of
CLLocationManager as well as Android's FusedLocationProviderApi and how
best to make them as efficient as possible.

I highly recommend user's avoid Mapbox GL until they acknowledge and fix
this serious flaw.

On Wednesday, October 7, 2015, Andrew Phillipo notifications@github.com
wrote:

Hey guys, seems to be like this could be wasting battery? Is there a way
to fix the pull request so that it can be merged? Seems like the guy who
wrote the library on background geo probably knows a bit about it's battery
use!


Reply to this email directly or view it on GitHub
#2120 (comment)
.

Snet form Gmail Mobile

@JAStanton
Copy link

Any updates on this?

@christocracy
Copy link
Author

Thankfully iOS 9 now requires a CLLocationManagerinstance to explicitly declare that it allowsBackgroundLocationUpdates in order for it to operate in background.

There's no reason MapBoxGL should ever declare locationManager.allowsBackgroundUpdates = YES.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS telemetry Integration with Mapbox Telemetry libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants