Skip to content
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

Allow developers to control whether battery monitoring is enabled #1476

Merged
merged 15 commits into from
Jun 14, 2018

Conversation

bsudekum
Copy link
Contributor

@bsudekum bsudekum commented Jun 7, 2018

Addresses part 1 of #1474

If an app sets UIDevice.isBatteryMonitoringEnabled on their own, we should not reset this property when initing/deiniting.

This new prop makes it so developers can control whether this UIDevice.isBatteryMonitoringEnabled is enabled internally.

/cc @mapbox/navigation-ios @simonseyer

@akitchen
Copy link
Contributor

akitchen commented Jun 7, 2018

Please don’t merge this as-is, as it hasn’t been discussed, groomed or prioritized yet.

This PR might not adequately address the issue - instead of introducing more state on RouteController, this should probably be delegated as requested.

@akitchen
Copy link
Contributor

akitchen commented Jun 7, 2018

My thoughts here: If we require battery monitoring for our own features, we should optionally delegate the decision to disable it when finished.

@bsudekum
Copy link
Contributor Author

bsudekum commented Jun 7, 2018

@akitchen how does something that looks like:

optional func routeController(_ routeController: RouteController, willChangeBatteryMonitoringState from: Bool, to: Bool) -> Bool

If implemented, we will adhere to whatever value the developer returns.

@simonseyer
Copy link

simonseyer commented Jun 8, 2018

Don’t know what the from value could be useful for (would always be !to, otherwise there would be no need to call the delegate). But in general looks good 👍

@bsudekum
Copy link
Contributor Author

bsudekum commented Jun 8, 2018

@simonseyer @akitchen moved to a delegate in c66becd.


super.init()

let monitorBatteryValue = delegate?.routeController?(self, willChangeBatteryMonitoringState: true) ?? true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delegate is always nil here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved in 573d582

@bsudekum
Copy link
Contributor Author

@akitchen updated and exposed the delegate only when deinit is called now.

- returns: A bool representing the value you would like `UIDevice.isBatteryMonitoringEnabled` set to.
*/
@objc(routeControllerWillDisableBatteryMonitoring:)
optional func routeControllerWillDisableBatteryMonitoring(_ routeController: RouteController) -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here might be confusing. Typically, a delegate method with "will" or "should" in the name returns a boolean to indicate whether to proceed with the described action.

So, a false response to routeControllerWillDisableBatteryMonitoring() would mean don't disable it. This might be more clear if we change "will" to "should", but in either case I think the logic should be the other way around from how it is currently implemented here.

@@ -316,7 +316,7 @@ open class RouteController: NSObject {
sendOutstandingFeedbackEvents(forceAll: true)
suspendNotifications()

let monitorBatteryValue = delegate?.routeControllerWillDisableBatteryMonitoring?(self) ?? false
let monitorBatteryValue = delegate?.routeControllerShouldDisableBatteryMonitoring?(self) ?? false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the semantics are still wrong: If I return false because it shouldn't be disabled, it will actually be disabled and the other way around.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; it's not correct to pass this value into the next line. The heuristic should look like:

  • If the delegate doesn't implement routeControllerShouldDisableBatteryMonitoring(), go ahead and disable it.
  • If the delegate implements routeControllerShouldDisableBatteryMonitoring() and returns true, disable it.
  • If the delegate implements routeControllerShouldDisableBatteryMonitoring() and returns false, don't disable it.

Copy link
Contributor

@akitchen akitchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the documentation update I think we're good to go here.

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 representing the value you would like `UIDevice.isBatteryMonitoringEnabled` set to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value here indicates whether to disable battery monitoring when the RouteController is deinited, not the value to set it to. If this method is not implemented, battery monitoring will be disabled when navigation ends.

With that doc change (or something close to it) I think we're good to merge this.

@akitchen
Copy link
Contributor

LGTM - thanks for the doc updates @bsudekum

@bsudekum bsudekum merged commit 99cd0f0 into master Jun 14, 2018
@bsudekum bsudekum deleted the control-battery branch June 14, 2018 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants