Command line tool camera permission

I try to write command line tool for recording from a camera using AVfoundation framework.

The problem that stuck my project is camera permission issue. Error message: "This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data".


I added Info.plist with NSCameraUsageDescription key and add request authorization for capture function but it seems that it ignored on runtime. I get the same error message when macOS should shows an alert asking the user to grant app access to the camera (AVCaptureDevice.requestAccess). I familiar with Info.plist and with NSCameraUsageDescription key from ios app that I wrote but it seem that it diffrent in command line tool.


If anyone know how I can solve this privacy issue it will be very helpful.


Thanks.

Replies

Im having the same issue now, have you found a solution for it?

SOLUTION:
1) Create a file with your editor, name it Info.plist, with this:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>NSMicrophoneUsageDescription</key>

<string>This app requires microphone acess to record your greeting.</string>

<key>CFBundleIdentifier</key>

<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>

<key>NSCameraUsageDescription</key>

<string>This app requires camera access to capture your dog photos.</string>

</dict>

</plist>


2) Drag it to your project checking Copy files if needed.


3) Go to Build Phases > Copy Files

4) Destination set to Products Directory
5) Add Info.plist
6) Uncheck “Copy only when installing”

Done! 😀

This issue is still actual: command line tool using avfoundation works only from terminal. Any attempts to launch it over ssh or as external process result in a crash. I've tried to create Info.plist like written above and put it to the folder with a tool - no luck. Also tried to write it to tool's binary as separate section - no luck too. Just for reference, here is the tool: https://github.com/mipops/dvrescue/tree/master/tools/avfctl
You may have luck by creating an Info.plist section in your command line tool's binary. The steps are documented in Adding an Info.plist to Single-File Tools.

Summarizing the steps here:
  1. Create an Info.plist file and make sure it has the keys CFBundleIdentifier and CFBundleName

  2. Add the usage description you need. NSCameraUsageDescription, in your case

  3. In the CLI target's build settings, set "Create Info.plist Section in Binary" to YES

  4. In the CLI target's build settings, set "Info.plist File" to the relative path to the Info.plist file you created in step 1

command line tool using avfoundation works only from terminal. Any
attempts to launch it over ssh

I wouldn’t expect that to work. When you log in via SSH your shell runs in a non-GUI login session and, as such, anything that involves the GUI is likely to behave weirdly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
  • Is there a way to bypass the GUI check, so you can access AVFoundation over ssh? I'm running into this same issue as well. Its my computer, I should be able to allow any app to access my camera, no matter how it is launched.

Add a Comment