Prompt the user to authorize access to the camera and microphone.
- Bundle Resources
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.
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:
If your app uses device cameras, include the
NSCamerakey in your app’s
If your app uses device microphones, include the
NSMicrophonekey in your app’s
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
authorization method before setting up a capture session. If the user has not yet granted or denied capture permission, the authorization status is
AVAuthorization. In this case, use the
request method to have macOS prompt the user:
request 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
PHAsset classes. These classes require read/write access to the Photos library, so you must use the use the
NSPhoto 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:
To reset the authorization state for camera access, type:
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.