tezvyn:

Track location continuously in the background

AI-drafted, machine-checkedSource: interviewintermediate
WHAT IT TESTS

Tuning Core Location for accuracy versus battery and enabling background updates.

OUTLINE

Set desiredAccuracy, distanceFilter, activityType; enable the Location background mode and allowsBackgroundLocationUpdates; request Always authorization.

WHAT THIS TESTS This evaluates whether you understand the tradeoffs in Core Location configuration and the concrete project setup that lets location continue while the app is backgrounded.

A GOOD ANSWER COVERS On the CLLocationManager you tune desiredAccuracy: kCLLocationAccuracyBestForNavigation or best while actively navigating, stepping down to hundredMeters when less precision is acceptable to save power. distanceFilter sets the minimum movement, in meters, before an update fires, throttling callbacks. activityType, such as automotiveNavigation or fitness, lets the system optimize sensor use and pause updates intelligently. For background operation you must enable the Location updates background mode in the target's Signing and Capabilities, set manager.allowsBackgroundLocationUpdates = true, and request Always authorization, which needs NSLocationAlwaysAndWhenInUseUsageDescription in Info.plist. You also handle the blue background-location status bar indicator and consider pausesLocationUpdatesAutomatically.

COMMON WRONG ANSWERS Forgetting to enable the Location updates background capability, so updates stop when backgrounded. Always using best accuracy, draining the battery. Requesting only when-in-use authorization for a background feature. Not setting allowsBackgroundLocationUpdates, which silently prevents background delivery despite the capability.

LIKELY FOLLOW-UPS When to prefer significant-location-change monitoring or region monitoring to save power when continuous precision is not needed. How showsBackgroundLocationIndicator behaves. The deferred updates API. Handling the user choosing approximate location.

ONE CONCRETE EXAMPLE For a navigation feature you set manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation, manager.activityType = .automotiveNavigation, manager.distanceFilter = 5, manager.allowsBackgroundLocationUpdates = true, and call manager.requestAlwaysAuthorization(). You tick Location updates under Background Modes and add the Always usage string. Now startUpdatingLocation() keeps delivering accurate fixes during turn-by-turn navigation even when the phone locks, while distanceFilter and activityType keep battery use reasonable when the user is stationary.

Read the original → developer.apple.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.