Working with Device Capabilities (Camera, Location, Notifications)
iOS Development — Architecture & Data
Chapter 8 · Working with Device Capabilities
Every capability this chapter covers — photos, location, notifications — touches something genuinely private to the user. Apple's own real platform enforces that seriously: most of them require an explicit, real permission prompt, and a real, specific reason string declared in advance.
Real, Required Privacy Descriptions
Before requesting access to almost any sensitive real capability, Xcode's own Info tab (or a
direct edit to Info.plist) needs a real, specific usage-description key — the actual message
shown to the user in the real system permission prompt.
Photos: PhotosPicker — A Real, Notable Exception
Introduced in iOS 16, SwiftUI's own real PhotosPicker is the current,
idiomatic way to let a user choose a photo.
PhotosPicker needs no real Info.plist privacy key at all —
it runs as a separate, real, sandboxed system process; the app itself never gains broad photo-library
access, only the specific real image(s) the user actually picks. This is a deliberate, real design choice
by Apple, not an oversight — a genuine, useful exception to this chapter's own opening rule.
Location: CLLocationManager
| Capability | Real Required Info.plist Key |
|---|---|
| Location (When in Use) | NSLocationWhenInUseUsageDescription |
Photos (PhotosPicker) | None required |
| Notifications | None required — authorized via a real runtime request instead |
CLLocationManagerDelegate's callback-based pattern remains the real, foundational way
location updates are delivered. Newer, async-sequence-based alternatives exist on more recent real OS
versions — worth investigating directly against Apple's own current documentation before adopting one, per
this course's own recurring discipline of verifying fast-moving APIs rather than assuming.
Notifications: UNUserNotificationCenter
requestAuthorization should be called once, real and early — typically at a natural moment
in the app's own flow, not immediately on first launch before the user has any context for why it's being
asked. A denied real prompt can only be reversed by the user, manually, in Settings — there's no real way
for the app to ask again.
Hands-On Exercises
Write a real func requestLocationAndNotify() async function that requests notification authorization via UNUserNotificationCenter, and — only if granted is true — schedules a real local notification confirming permission was granted.
Explain, in your own words, what would actually happen at runtime if NSLocationWhenInUseUsageDescription were missing from Info.plist and requestWhenInUseAuthorization() were called anyway.
Explain, in your own words, why PhotosPicker needing no Info.plist key at all is a genuine, deliberate privacy design choice, rather than an inconsistency or an oversight compared to location and camera access.
Chapter 8 Quick Reference
- Most sensitive real capabilities need a real, specific
Info.plistusage-description key — missing one causes a genuine crash, not a graceful error PhotosPicker(iOS 16) needs no privacy key at all — a real, deliberate exception, since it runs as a separate sandboxed system processCLLocationManager's realrequestWhenInUseAuthorization()+CLLocationManagerDelegatepattern requiresNSLocationWhenInUseUsageDescriptionUNUserNotificationCenter.requestAuthorization(options:)— real, current async permission request; a denied prompt can only be reversed manually in Settings- A real local notification is built from
UNMutableNotificationContent+ a trigger +UNNotificationRequest, added viaUNUserNotificationCenter.current().add(request)