Skip to content

Ios Corelocation Permission

DodaTech 2 min read

In this tutorial, you'll learn about How to Fix iOS CoreLocation Permission Not Working. We cover key concepts, practical examples, and best practices.

The Problem

Core Location does not work:

Requesting location but no permission dialog appears.

or:

Delegate callbacks are not firing.

Quick Fix

Step 1: Add location usage descriptions to Info.plist

WRONG — missing Info.plist keys:

<!-- Info.plist -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Required for...</string>

RIGHT — add the correct key for your use case:

<key>NSLocationWhenInUseUsageDescription</key>
<string>App needs location to show nearby places</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App needs location for background tracking</string>

Step 2: Request permission in code

import CoreLocation

let locationManager = CLLocationManager()

// Request permission:
locationManager.requestWhenInUseAuthorization()
// or:
locationManager.requestAlwaysAuthorization()

Step 3: Check authorization status

func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
    switch manager.authorizationStatus {
    case .authorizedWhenInUse, .authorizedAlways:
        manager.startUpdatingLocation()
    case .denied, .restricted:
        // Show alert directing user to Settings
        break
    case .notDetermined:
        manager.requestWhenInUseAuthorization()
    @unknown default:
        break
    }
}

Step 4: Handle denied permission

If the user denied, redirect to Settings:

func showLocationSettingsAlert() {
    let alert = UIAlertController(title: "Location Required",
        message: "Enable location in Settings", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Settings", style: .default) { _ in
        UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
    })
    present(alert, animated: true)
}

Step 5: Set the delegate

locationManager.delegate = self

Step 6: Start updating location

locationManager.startUpdatingLocation()

Prevention

  • Add all required Info.plist keys before using Core Location.
  • Check authorizationStatus before calling startUpdatingLocation().
  • Handle both .denied and .notDetermined states.

Common Mistakes with corelocation permission

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world IOS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between WhenInUse and Always authorization?

WhenInUse works only when the app is in the foreground. Always works in the background too and requires additional justification during App Store review.

Why does my location permission dialog not appear?

The Info.plist entry is missing, or the permission was already denied. Check the authorization status first.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro