How to Request Camera Permission in iOS Guide
In this article
Yes, you can request camera permission in iOS by adding a usage description to the app’s Info.plist and then calling AVCaptureDevice.requestAccess(for: .video) at runtime.
What You’ll Need
- Xcode installed on a macOS machine (any recent version that supports Swift 5).
- An Xcode project that targets iOS 11 or later.
- Basic familiarity with Swift and the iOS project structure.
- An iPhone, iPad, or the iOS Simulator for testing.
Step‑by‑Step
-
Open the project in Xcode. Navigate to the project navigator, select the
.xcworkspaceor.xcodeprojfile, and make sure the target you intend to modify is highlighted. -
Add the privacy key to
Info.plist. In the project navigator, locateInfo.plist. Right‑click and choose Open As > Source Code or use the property‑list editor. Add a new row with the keyPrivacy - Camera Usage Description(the raw key isNSCameraUsageDescription) and provide a short, user‑facing string such as "We need access to the camera to let you scan QR codes."
The exact wording appears in the system permission dialog, so keep it clear and concise. -
Import the AVFoundation framework. In any Swift file where you plan to request the camera, add:
import AVFoundation -
Check the current authorization status (optional but recommended). Before prompting the user, you can read the existing status:
let status = AVCaptureDevice.authorizationStatus(for: .video) switch status { case .authorized: // Already have permission – proceed. case .notDetermined: // Permission has not been asked yet – request now. case .denied, .restricted: // Show an alert directing the user to Settings. } -
Request access. When the status is
.notDetermined, call the request method on the main thread:
The closure runs on a background queue, so any UI updates must be dispatched back to the main queue.AVCaptureDevice.requestAccess(for: .video) { granted in DispatchQueue.main.async { if granted { // Permission granted – initialise camera session. } else { // Permission denied – present a helpful alert. } } } -
Handle the denial gracefully. If the user taps "Don’t Allow," you cannot program‑matically show the system dialog again. Instead, display an in‑app alert that explains why the camera is essential and offers a button that opens the Settings app:
if let appSettings = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(appSettings) } - Test on a real device. The simulator can simulate permission dialogs, but real‑world behaviour (especially the Settings‑app flow) is only verifiable on a physical iPhone or iPad.
-
Build and run. Press ⌘R to launch the app. The first time the request code executes, iOS will present the permission alert with the string you added to
Info.plist. Verify that the alert appears, that the response is captured correctly, and that the camera session starts only after a positive grant.
Common Mistakes
- Forgetting to add
NSCameraUsageDescription– iOS will terminate the app with a runtime exception. - Using the wrong enum value (e.g.,
.audioinstead of.video) – the request will succeed for the wrong media type and the camera will still be blocked. - Calling
requestAccessfrom a background thread without returning to the main queue for UI updates – this can cause UI glitches or crashes. - Assuming the permission dialog will appear every launch – iOS only shows it once; subsequent launches rely on the stored status.
- Hard‑coding the usage description string in code instead of the
Info.plistentry – the system ignores it and the app crashes.
Tips
- Request the camera as early as possible, ideally before the user reaches a screen that needs it. This reduces friction.
- Provide a short, context‑specific explanation before the system dialog, such as a custom modal that says "We need the camera to scan your ID." This improves acceptance rates.
- Cache the authorization status in a property if you need to check it frequently, but always call
authorizationStatusto stay up‑to‑date after the user changes settings. - When directing users to Settings, add a clear call‑to‑action button labeled "Open Settings" rather than a generic "OK".
- If your app supports both iPhone and iPad, test the permission flow on both size classes – the alert layout is identical, but custom UI may need adjustments.
Troubleshooting
If the permission dialog never appears, follow these steps in order:
- Restart the app. A stale process can cache an old status.
- Delete the app from the device and reinstall. This clears the stored privacy settings for that bundle identifier.
- Verify the
Info.plistentry. Open the file as source code and ensure the key is exactlyNSCameraUsageDescription(case‑sensitive) and that the string value is not empty. - Check the target’s deployment version. The key is required on iOS 11+, but older deployment targets may behave differently.
- Inspect the console log. Xcode will print messages like "[Privacy] Camera usage description missing" if the key is absent.
- Reset all privacy settings. On the device, go to Settings → General → Reset → Reset Location & Privacy. This forces iOS to ask again for every permission.
- Confirm that the request is executed on the main thread. If you see UI not updating, wrap the call in
DispatchQueue.main.async.
If none of the above resolves the issue, consider creating a minimal test project that only contains the permission request code. If the test project works, the problem likely lies in other parts of your original app (e.g., a conflicting Info.plist entry or a custom entitlement).
Frequently Asked Questions
Do I need to request camera permission for the simulator?
The iOS Simulator does simulate the permission dialog, but you can also reset its privacy settings via the menu: Simulator → Reset Content and Settings.
Can I request camera permission without showing the system alert?
No. iOS requires the system‑provided alert for privacy reasons. You can only precede it with your own explanatory UI.
What happens if the user denies permission and later changes it in Settings?
The next time you call authorizationStatus(for: .video), it will return .authorized. You should re‑check the status before starting a camera session.
Is there a way to request both camera and microphone in a single call?
Each media type has its own request method. You must call requestAccess(for: .video) and requestAccess(for: .audio) separately.
Why does my app crash with "This app has crashed because it attempted to access privacy-sensitive data without a usage description"?
This crash occurs when the required NSCameraUsageDescription key is missing or misspelled in Info.plist. Adding the correct key resolves the issue.
Can I change the permission dialog text after the app is released?
Yes. Updating the string value for NSCameraUsageDescription in a new app version will change the text shown in future permission prompts.