Article

Requesting Authorization for Media Capture on iOS

Respect user privacy by seeking permission to capture and store photos, audio, and video.

Overview

In iOS, the user must explicitly grant permission for each app to access cameras and microphones. Before your app can use the capture system for the first time, iOS shows an alert asking the user to grant your app access to the camera, as shown below. iOS remembers the user’s response to this alert, so subsequent uses of the capture system don’t cause it to appear again. The user can change permission settings for your app in Settings > Privacy.

Screenshot of iOS camera permission alert with app-specific message

To make sure your app has permission before capturing media, follow the steps below.

Configure Your App's Info.plist File

iOS requires that your app provide static messages to display to the user when the system asks for camera or microphone permission:

For each key, provide a message that explains to the user why your app needs to capture media, so that the user can feel confident granting permission to your app.

Verify and Request Authorization for Capture

Always test the AVCaptureDevice authorizationStatus(for:) method before setting up a capture session. If the user has not yet granted or denied capture permission, the authorization status is AVAuthorizationStatus.notDetermined. In this case, use the requestAccess(for:completionHandler:) method to tell iOS to prompt the user:

switch AVCaptureDevice.authorizationStatus(for: .video) {
    case .authorized: // The user has previously granted access to the camera.
        self.setupCaptureSession()
    
    case .notDetermined: // The user has not yet been asked for camera access.
        AVCaptureDevice.requestAccess(for: .video) { granted in
            if granted {
                self.setupCaptureSession()
            }
        }
    
    case .denied: // The user has previously denied access.
        return

    case .restricted: // The user can't grant access due to restrictions.
        return
}

The requestAccess(for:completionHandler:) method is asynchronous: Your app continues running while iOS shows the permission alert. When the user responds, the system calls your completion handler. If the completion handler’s success parameter is true, you can proceed to set up and start a capture session.

Request Authorization Before Saving Captured Media

After capturing photos or video, you may want to save them into the user’s Photos library. Accessing the Photos library also requires user permission (separate from camera and microphone permission). How and when you request permission depends on which features you use for saving media:

See Also

Camera and Microphone

Requesting Authorization for Media Capture on macOS

Prompt the user to authorize access to the camera and microphone.

property list key NSCameraUsageDescription

A message that tells the user why the app is requesting access to the device’s camera.

Name: Privacy - Camera Usage Description
property list key NSMicrophoneUsageDescription

A message that tells the user why the app is requesting access to the device’s microphone.

Name: Privacy - Microphone Usage Description