Contents

Requesting Authorization for Media Capture on macOS

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

Overview

In macOS 10.14 and later, 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, macOS shows an alert asking the user to grant your app access to the camera, as shown below. macOS 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 System Preferences > Security & Privacy. The request for authorization looks different from the alert UI in iOS.

[Image]

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

Configure Your Camera and Microphone Apps

The information property list keys for Camera and Microphone in macOS operate the same way as they do in iOS. macOS 10.14 and later populates the static messages with these strings 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.

[Image]

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 have macOS prompt the user:

The requestAccess(for:completionHandler:) method is asynchronous: Your app continues running while macOS 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). For most photo and video capture workflows (including Live Photos and RAW format capture), use the PHPhotoLibrary and PHAssetCreationRequest classes. These classes require read/write access to the Photos library, so you must use the use the NSPhotoLibraryUsageDescription key in your information property list to provide a message to the user when asking for access. For details, see Saving captured photos.

Reset Authorization from Terminal

To reset the state of the user’s decision to grant or reject Microphone access so the prompt shows again, open Terminal and input the command:

tccutil reset Microphone

To reset the authorization state for camera access, type:

tccutil reset Camera

This command resets the access authorization settings for all apps, so other apps will prompt the user again. Use this tool to debug the appearance of your privacy justification strings and their localized versions.

See Also

Camera and sound