Thuta Learning
IntermediateMobile Developmentintermediate

Runtime Permissions Basics

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Runtime Permissions Basics with nothing to be intimidated by
  • Get comfortable running Xcode/SwiftUI code yourself
  • Be able to apply this concept in a real project right away

Let's think about it this way for a second

We already covered adding a usage description string in `Info.plist` back in the Basics chapter — calling an iOS API (Camera, Location) automatically shows the system dialog (unlike Android, where you'd need to manually trigger something like `rememberLauncherForActivityResult`), and the user can choose 'Allow' or 'Don't Allow'. Location permission can be split into two levels of granularity: 'While Using App' / 'Always' — App Store review checks 'Always' (background location) especially strictly.

Let's connect this to a real-world scenario

In an app with a location feature, calling `CLLocationManager().requestWhenInUseAuthorization()` immediately brings up a system dialog containing the `NSLocationWhenInUseUsageDescription` string from `Info.plist` — you can only get location data once the user taps 'Allow', and if they choose 'Don't Allow' you need to handle that gracefully.

Let's look at it together

swift
import CoreLocation

class LocationManager: NSObject, ObservableObject {
    private let manager = CLLocationManager()

    override init() {
        super.init()
        manager.delegate = self
    }

    func requestPermission() {
        manager.requestWhenInUseAuthorization()
    }
}

extension LocationManager: CLLocationManagerDelegate {
    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
        print("Authorization status: \(manager.authorizationStatus)")
    }
}
You should see
Calling `requestPermission()` brings up the system location permission dialog, and choosing 'Allow' shows authorizationStatus changing in the Console.

5-minute try-it

Write your own `LocationManager`, add `NSLocationWhenInUseUsageDescription` to `Info.plist`, and trigger the permission dialog on the Simulator — try choosing both 'Allow' and 'Don't Allow'.

A quick heads-up

Once the user picks 'Don't Allow', your app can't show the dialog again — they'll need to go to Settings manually, so your app should show guidance like 'please open Settings'.

Easy traps

  • Calling a location/camera API without adding a usage description string in `Info.plist` — the app will crash immediately (a stricter failure mode than on Android)
  • Requesting background location ('Always') when it isn't actually needed for a core feature — this can get your app rejected in App Store review

Now try it yourself

Write your own `LocationManager`, add `NSLocationWhenInUseUsageDescription` to `Info.plist`, and trigger the permission dialog on the Simulator — try choosing both 'Allow' and 'Don't Allow'.

You'll know it worked when: Calling `requestPermission()` brings up the system location permission dialog, and choosing 'Allow' shows authorizationStatus changing in the Console.

Runtime Permissions Basics | Thuta Learning