Fixing a location feature that drains the battery

Platform & distribution Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

A 'nearby deals' feature needs city-level accuracy but uses best accuracy continuously. Fix?

Options
Hint 1 of 1

What accuracy does the feature need?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Lower desiredAccuracy to about a kilometre, add a distanceFilter, and stop updates when the screen closes

Correct. It meets the need with far less power.

Why not the others?
  • B Keep best accuracy but update less often with a Timer. GPS stays on, and timers don't run when suspended.
  • C Request Always permission. More permission doesn't save battery.
  • D Cache the last location forever. Stale location breaks the feature.

30-second answer

Measure first with the Energy instrument and Organizer. Then use the least power that meets the need: lower desiredAccuracy, a distanceFilter, the right activityType with automatic pausing, significant-change or CLMonitor conditions instead of continuous GPS, and stop updates when the feature isn't visible or needed. Avoid background location unless the feature depends on it.

Practise saying it · 45 s. No recording, just a timer

Explain how you cut location battery use.

Say your answer out loud, then check which of these points you covered:

  • Measure
  • Lower accuracy
  • Cheaper APIs
  • Stop when done

Deep dive

Best accuracy uses GPS; hundred-metre accuracy can use Wi-Fi and cells.

pausesLocationUpdatesAutomatically stops updates when the user is still.

Visits monitoring is a low-power way to learn significant places.

Show the location indicator honestly; users notice.

Common mistakes

  • Best accuracy for a city-level feature.
  • Never calling stop.

Senior take & follow-ups

Seniors map the feature's real accuracy need to the cheapest API.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does distanceFilter do?

    Show hint

    Suppresses updates until the device moves that far.

  2. What is the cheapest background signal?

    Show hint

    Significant-change or visit monitoring.

Suggest a fix if something here is wrong or out of date.