Skip to content

Commit

Permalink
Merge pull request #1476 from mapbox/control-battery
Browse files Browse the repository at this point in the history
Allow developers to control whether battery monitoring is enabled
  • Loading branch information
Bobby Sudekum authored Jun 14, 2018
2 parents a9d45a4 + 8c59f04 commit 99cd0f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Added `NavigationMapView.recenterMap()` for recentering the map if a user gesture causes it to stop following the user. ([#1471](https://github.com/mapbox/mapbox-navigation-ios/pull/1471))
* Moved `RouteController.tunnelSimulationEnabled` to `TunnelIntersectionManager.tunnelSimulationEnabled`. ([#1489](https://github.com/mapbox/mapbox-navigation-ios/pull/1489))
* Deprecated `NavigationViewController.usesNightStyleInsideTunnels`. Style switching is enabled as a side effect of `TunnelIntersectionManager.tunnelSimulationEnabled`, which is set to `true` by default. ([#1489](https://github.com/mapbox/mapbox-navigation-ios/pull/1489))
* Added `RouteControllerDelegate.routeControllerWillDisableBatteryMonitoring(_:)` which allows developers control whether battery monitoring is disabled when `RouteController.deinit()` is called.

## v0.18.0 (June 5, 2018)

Expand Down
22 changes: 21 additions & 1 deletion MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ public protocol RouteControllerDelegate: class {
*/
@objc(routeController:shouldPreventReroutesWhenArrivingAtWaypoint:)
optional func routeController(_ routeController: RouteController, shouldPreventReroutesWhenArrivingAt waypoint: Waypoint) -> Bool


/**
Called when the route controller will disable battery monitoring.

Implementing this method will allow developers to change whether battery monitoring is disabled when `RouteController` is deinited.

- parameter routeController: The route controller that will change the state of battery monitoring.
- returns: A bool indicating whether to disable battery monitoring when the RouteController is deinited.
*/
@objc(routeControllerShouldDisableBatteryMonitoring:)
optional func routeControllerShouldDisableBatteryMonitoring(_ routeController: RouteController) -> Bool
}

/**
Expand Down Expand Up @@ -293,7 +305,15 @@ open class RouteController: NSObject {
sendCancelEvent(rating: endOfRouteStarRating, comment: endOfRouteComment)
sendOutstandingFeedbackEvents(forceAll: true)
suspendNotifications()
UIDevice.current.isBatteryMonitoringEnabled = false

guard let shouldDisable = delegate?.routeControllerShouldDisableBatteryMonitoring?(self) else {
UIDevice.current.isBatteryMonitoringEnabled = false
return
}

if shouldDisable {
UIDevice.current.isBatteryMonitoringEnabled = false
}
}

func startEvents(accessToken: String?) {
Expand Down

0 comments on commit 99cd0f0

Please sign in to comment.