M-Swift All articles
Testing & Tooling

Access Isn’t a One-Time Deal: Auditing Swift Permissions After Launch

M-Swift
Access Isn’t a One-Time Deal: Auditing Swift Permissions After Launch

Photo: iPhone privacy settings permissions screen developer testing on device, via substackcdn.com

The permission sheet at onboarding feels like a contract. It isn’t. It’s a snapshot. Users tap Allow, you ship, and everyone moves on—until someone switches Photos to Limited, turns off notifications in Settings, or picks Allow Once for location and forgets. Your code still believes it has access. That gap is permission drift, and it’s one of the quietest sources of support tickets in iOS apps.

Permission States Are Not Booleans

A lot of Swift code compresses permission state into a bool on day one and never recovers. You’ll see something like let granted = PHPhotoLibrary.authorizationStatus(for: .readWrite) == .authorized. That single line throws away .limited for photos, .provisional for notifications, and the difference between .authorizedWhenInUse and .authorizedAlways for location. The fix isn’t a giant switch in every view controller. It’s a small, boring wrapper that preserves the real state and lets each feature ask for what it actually needs.

enum PhotoAccess {
    case full, limited, denied, undetermined
}

func currentPhotoAccess() -> PhotoAccess {
    switch PHPhotoLibrary.authorizationStatus(for: .readWrite) {
    case .authorized: return .full
    case .limited: return .limited
    case .denied, .restricted: return .denied
    case .notDetermined: return .undetermined
    @unknown default: return .denied
    }
}

That wrapper becomes the source of truth. Views don’t call the system framework directly; they ask the wrapper. When the state changes, you invalidate one object instead of hunting down twelve scattered checks.

Map Every Path That Assumes Access

Before you touch code, list the features that depend on a permission and what happens when it disappears mid-session. Camera capture. Photo library reads. Location for nearby results. Push registration. Contacts import. Microphone for voice notes. App Tracking Transparency, if you use it. For each one, write down three things: the happy path, the degraded path, and the recovery path. A spreadsheet is fine. The point is to stop treating “permission granted” as a permanent property of the app.

A useful question for each feature: what does the user see if this permission is revoked while the app is backgrounded? If the answer is a spinner, an empty screen, or a crash, you’ve found work.

Recheck When the App Comes Back

The Settings app is one swipe away. Users revoke access while your app is suspended, then return expecting the app to know. If you only check permission in viewDidLoad, you’ll show a camera preview that never starts or a map stuck at the last location. Use scenePhase or UIApplication.didBecomeActiveNotification to refresh cached state when the app becomes active.

@Environment(\.scenePhase) private var scenePhase

.onChange(of: scenePhase) { _, newPhase in
    if newPhase == .active {
        refreshPermissionState()
    }
}

Don’t block the foreground with a spinner every time. The system checks are cheap. Re-read the state, update your wrapper, and let SwiftUI or UIKit react. If a feature needs an async notification settings call, kick it off and update when it returns—just don’t make the whole app wait on it.

Design for the Awkward Middle

Limited photo access is not denial. If the user picked twelve photos, your gallery grid should show those twelve and an “Add More” cell, not an empty state that says “No access.” Approximate location is not failure either. You can still show city-level results; don’t throw up a wall that says “Location required” when the user deliberately chose a coarser signal. Provisional notifications are delivered quietly to Notification Center, so don’t assume a banner appeared. And .notDetermined is not denial—it means you haven’t asked yet, or the user dismissed the prompt without a decision.

The common mistake is designing two states: allowed and denied. Real users live in the middle. Build the middle screens first and the happy path becomes easier.

The “Allow Once” Trap

Location’s Allow Once option expires. The next launch, you may be back to .notDetermined or .denied depending on how the user dismissed it. If your app treats that as “the user hates location,” you’ll either nag at launch or hide a feature that would work fine with a contextual ask. A coffee shop app should request location when someone taps “Find nearby,” not when the app opens. Context makes the prompt make sense, and it makes a second ask less annoying.

Don’t game the system by requesting repeatedly. Just make sure your code treats Allow Once as a temporary grant, not a permanent one. If the user granted it for this session, use it. When it expires, fall back gracefully and ask again only when the feature is actually needed.

A Device Test Matrix That Catches This

The Simulator is great for resetting permissions quickly, but it doesn’t model every real-world edge case. Keep at least one physical iPhone in the loop. Test these states before every release that touches permissions:

  1. Fresh install, deny everything. Confirm the app is still usable.
  2. Allow all, then revoke Photos in Settings while the app is backgrounded. Return to the app and check the gallery.
  3. Limited Photos: select three items, then add one from inside the app’s picker. Confirm the grid updates.
  4. Location: choose Allow Once, force quit, relaunch. Confirm the app doesn’t treat the user as permanently denied.
  5. Notifications: allow, then turn off banners but keep alerts. Confirm your in-app messaging doesn’t lie about delivery.
  6. Provisional notifications, if you use them: check Notification Center instead of the lock screen.
  7. ATT: deny tracking, relaunch, and confirm you don’t re-prompt or break unrelated flows.

Add a tiny debug screen that prints current permission states in builds you ship to QA. It’s faster than asking someone to walk through Settings five times.

Make It a Habit

Permission drift isn’t an edge case. It’s Tuesday. Users change their minds, and iOS gives them plenty of ways to do it. The teams that handle this well aren’t writing more code—they’re writing less code that assumes access. Centralize the state, recheck on foreground, design the middle states, and put the matrix in your release checklist. Then the next “Allow Once” won’t turn into a support ticket.

All Articles

Related Articles

The Return Key Is a Lie: Auditing SwiftUI Text Input on Real Hardware

The Return Key Is a Lie: Auditing SwiftUI Text Input on Real Hardware

Translation Isn't Localization: A Swift Pre-Ship Audit for the Locales You Never Opened

Translation Isn't Localization: A Swift Pre-Ship Audit for the Locales You Never Opened

Noon Is a Moving Target: Hardening Swift Calendar Logic for Real-World Time

Noon Is a Moving Target: Hardening Swift Calendar Logic for Real-World Time