What is Core Location in iOS?
Answer
Core Location provides device location and heading information — GPS, Wi-Fi positioning, cell towers, and iBeacon. Usage requires explicit user permission. Setup: add to Info.plist: NSLocationWhenInUseUsageDescription — explains why you need location. Implementation: import CoreLocation class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { private let manager = CLLocationManager() @Published var userLocation: CLLocation? @Published var authorizationStatus: CLAuthorizationStatus override init() { super.init() manager.delegate = self manager.desiredAccuracy = kCLLocationAccuracyBest } func requestPermission() { manager.requestWhenInUseAuthorization() } func startUpdating() { manager.startUpdatingLocation() } func stopUpdating() { manager.stopUpdatingLocation() } // Delegate: func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { userLocation = locations.last } func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { authorizationStatus = manager.authorizationStatus switch manager.authorizationStatus { case .authorizedWhenInUse, .authorizedAlways: startUpdating() case .denied, .restricted: print("Location access denied") default: break } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Location error: \(error)") } }. Authorization levels: .authorizedWhenInUse (in foreground), .authorizedAlways (foreground + background — justify to App Review), .denied, .restricted, .notDetermined. One-time location: manager.requestLocation() — single update, simpler for one-off needs. Region monitoring: get notified when device enters/exits a circular region (geofencing).