Requesting Location Authorization
Handle permissions and privacy correctly.
Why Location Needs Permission
On Apple platforms, accessing the user's location is a privacy-sensitive operation. Your app must explicitly request authorization before Core Location will deliver any coordinates. The system shows a permission dialog the first time you ask.
- Authorization is granted per-app by the user.
- You cannot bypass it programmatically.
import CoreLocation
let manager = CLLocationManager()Info.plist Usage Description Keys
Before requesting authorization you must add a usage description string to Info.plist. These strings are shown to the user in the permission dialog. The two key ones are:
NSLocationWhenInUseUsageDescription— for foreground-only access.NSLocationAlwaysAndWhenInUseUsageDescription— for background access too.
Omitting the relevant key causes the request to silently fail or crash.
<!-- Info.plist -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to show nearby places.</string>All lessons in this course
- Requesting Location Authorization
- Getting the User's Location
- Displaying Maps in SwiftUI
- Geocoding and Regions