In Core Location, how does CLLocationUpdate.liveUpdates differ from CLLocationManager's delegate updates, and how does each trade accuracy against battery?
answer
- push to a delegate versus a sequence
- for try await over updates
- one configuration instead of several knobs
- desiredAccuracy and distanceFilter defaults
- iOS 18 diagnostics on each update
basics
~10 sliveUpdates(:), added in iOS 17, returns an async sequence of CLLocationUpdate values tuned by one LiveConfiguration. The delegate API pushes arrays to locationManager(:didUpdateLocations:) and is tuned with desiredAccuracy, distanceFilter, activityType and automatic pausing.
solid answer
~40 s`CLLocationUpdate.liveUpdates(_:)` returns an async sequence: updates start when you iterate it with `for try await` and stop when the loop ends, and if the app has not asked for permission yet, iterating triggers the when-in-use prompt. Its only parameter is a `LiveConfiguration` (`.default`, `.automotiveNavigation`, `.otherNavigation`, `.fitness`, `.airborne`, plus `.maritime` in iOS 27), which tells Core Location what kind of movement to expect. From iOS 18 each update also explains gaps through flags such as `authorizationDenied`, `accuracyLimited` and `stationary`. The delegate API calls `startUpdatingLocation()` and delivers arrays to `locationManager(_:didUpdateLocations:)` on the run loop of the thread that created the manager. Its battery knobs are explicit: `desiredAccuracy` defaults to `kCLLocationAccuracyBest` on iOS and `distanceFilter` to `kCLDistanceFilterNone`, so lowering accuracy and raising the filter lets Core Location power radios down.
code
swift · 29 linesimport CoreLocation
@MainActor
final class RouteRecorder {
private(set) var route: [CLLocation] = []
private var isRecording = false
func start() {
isRecording = true
Task {
do {
for try await update in CLLocationUpdate.liveUpdates(.fitness) {
if !isRecording { break } // End Walk was tapped
if let location = update.location {
route.append(location)
} else if #available(iOS 18.0, *), update.authorizationDenied {
break // the walker said no: stop and show a Settings hint
}
}
} catch {
// the sequence threw: mark the walk as interrupted
}
}
}
func stop() {
isRecording = false // the loop exits on the next update
}
}go deeper
Recall that one API uses a delegate and the other an async sequence, and name desiredAccuracy and distanceFilter as the battery settings on the manager.
Explain the defaults, which thread delegate callbacks use, how a live-updates loop starts and stops, and what each LiveConfiguration case tells Core Location.
Use the iOS 18 diagnostics to tell a denied, limited or stationary gap apart, and keep iOS 17 deployments compiling with availability checks.
Decide whether a codebase standardises on live updates or the delegate API, weighing explicit power tuning against simpler concurrency code and newer diagnostics.
## Two front ends for the same location service Core Location's **standard location service** produces the most precise and regular positions, using GPS, Wi-Fi and cellular radios as needed. An app can consume it in two ways: - the long-standing **delegate API**: configure a `CLLocationManager`, call `startUpdatingLocation()`, and receive callbacks on a `CLLocationManagerDelegate`; - **live updates**, added in iOS 17: call `CLLocationUpdate.liveUpdates(_:)` and iterate the returned `CLLocationUpdate.Updates` async sequence. Both reach the same hardware and the same authorization rules. They differ in how you start and stop them, how you tune them and how they report problems. ## The delegate API and its power knobs With a manager, every behaviour is a property you set before starting: - `desiredAccuracy`: how precise a fix you want. On iOS the default is `kCLLocationAccuracyBest`; values such as `kCLLocationAccuracyHundredMeters` or `kCLLocationAccuracyKilometer` let Core Location use cheaper hardware and turn it off sooner. - `distanceFilter`: the minimum horizontal movement, in meters, before a new update. The default `kCLDistanceFilterNone` reports every movement; a larger value lets radios sleep between updates. - `activityType`: a `CLActivityType` such as `.fitness` or `.otherNavigation` that helps Core Location decide when to pause. The default is `.other`. - `pausesLocationUpdatesAutomatically`: `true` by default on iOS, letting Core Location pause when the position is unlikely to change. - `requestLocation()`: a one-shot fix delivered to the same delegate method, for screens that need a position once. It cannot run alongside `startUpdatingLocation()`; starting continuous updates cancels it. Updates arrive in `locationManager(_:didUpdateLocations:)` as an array in chronological order, and errors in `locationManager(_:didFailWithError:)`. Core Location calls the delegate on the run loop of the thread that created the manager, so it is normally created on the main thread. Calling `startUpdatingLocation()` again while running does not force a fresh fix; stopping in between does. ## Live updates as an async sequence The newer API trades those knobs for one value and Swift concurrency: 1. Call `CLLocationUpdate.liveUpdates(.fitness)` (or another `LiveConfiguration`) to get the sequence. 2. Iterate it with `for try await update in ...` inside a `Task`. If the app has never asked for authorization, Core Location prompts for when-in-use when iteration starts. 3. Read `update.location`, which is `nil` when an update reports a state change rather than a position. 4. Leave the loop with `break` or `return` to stop; Apple notes the loop does not end on its own. `LiveConfiguration` has `.default`, `.automotiveNavigation`, `.otherNavigation`, `.fitness` and `.airborne`; iOS 27 adds `.maritime`. There is no `desiredAccuracy` or `distanceFilter` on this path: the configuration is the only parameter, and Core Location chooses the hardware. ## Diagnostics in iOS 18 In iOS 17 a live update carries little more than `location` and `isStationary`. iOS 18 adds Boolean diagnostics that explain why positions stopped: `authorizationDenied`, `authorizationDeniedGlobally`, `authorizationRestricted`, `insufficientlyInUse`, `locationUnavailable`, `accuracyLimited`, `serviceSessionRequired` and `authorizationRequestInProgress`. The SDK marks `isStationary` deprecated and renamed to `stationary`, which itself needs iOS 18, so code deploying to iOS 17 guards those reads with `#available`. | Concern | Delegate API | liveUpdates | |---|---|---| | Available since | iOS 2 (`didUpdateLocations` iOS 6) | iOS 17 | | Start and stop | `startUpdatingLocation()` / `stopUpdatingLocation()` | begin iterating / leave the loop | | Tuning | accuracy, distance filter, activity type, pausing | one `LiveConfiguration` | | Why updates stopped | `didFailWithError`, pause callbacks | per-update flags from iOS 18 | | One-shot fix | `requestLocation()` | take the first update with a location | ## Choosing for a dog-walking app For recording a walk's route, either API works. Live updates with `.fitness` keep the code short and give clear diagnostics on iOS 18; the delegate API is the choice when the team needs an explicit `distanceFilter` (say 10 meters, so a walker standing at a lamp post produces no points) or already has a manager-based service. For the nearest-waiting-dogs list, `requestLocation()` with `kCLLocationAccuracyHundredMeters` gives one cheap fix instead of a running stream. In both cases, the biggest battery saving is the one Apple stresses first: stop the service as soon as the feature no longer needs positions. Apple's guidance also says to start location services only when someone uses a feature that needs them, so neither the manager nor the live-updates loop should start at app launch just to have a position ready.
- How does the route recorder stop a liveUpdates stream cleanly?Leave the `for try await` loop with `break` or `return`; Apple's documentation notes the loop does not end on its own. A common pattern keeps an `isRecording` flag, sets it to false on End Walk and breaks on the next update. Leaving the loop is what ends delivery to that iteration, so no separate stop call exists on this API.
- On iOS 18, what does an update with stationary set to true tell the recorder?Core Location stopped delivering positions because the device is not moving, and it may hold further updates until the walker moves again or the location becomes unknown. The recorder should treat the gap as a pause in the walk, not a failure. The SDK marks the iOS 17 name `isStationary` deprecated and renamed to `stationary`, which requires iOS 18.
- liveUpdates takes desiredAccuracy and distanceFilter just like a CLLocationManager.
- kCLLocationAccuracyBestForNavigation is a sensible default for any location screen.
- Calling startUpdatingLocation() again immediately delivers a fresh location fix.
- distanceFilter also throttles significant-change updates.
- update.stationary can be read on any iOS 17 device.
Assumes an iOS 17 deployment target built with the iOS 27.1 SDK: liveUpdates is iOS 17, the per-update diagnostics and stationary are iOS 18, and the maritime configuration is iOS 27.