'How do I debug an app on the Mac that accesses the camera?

My Qt C++ app captures video from the camera on the Mac. It has the NSCameraUsageDescription value set in its plist file. But, not surprisingly, this doesn't help if I am running it using lldb, either from the commandline or from Qt Creator. It just crashes with the line:

2020-02-28 15:32:14.462735-0500 mqtt[47726:867880] [access] 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.

So how do I do that for lldb? It is in Qt Creator's Info.plist but I guess that doesn't help if it is running via lldb.



Solution 1:[1]

To allow your application to access the camera, you should have a Info.plist file with the field NSCameraUsageDescription filled with something.

If you're not building an application bundle (.app), then you can put the Info.plist next to your executable. Then the next time you run it with lldb it will ask for authorization to access the camera. Once you give it once, you might have to close the application and start it again.

According to my test, the following Info.plist content is enough :

<?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>NSCameraUsageDescription</key>
    <string>Video Input</string>
</dict>
</plist>

Solution 2:[2]

Since macOS Monterey (maybe also earlier versions) the app no longer crashes when the Info.plist is adjusted, but unfortunately it also does NOT show a camera image. Instead the view only shows a black screen. It looks like macOS only allows access to the camera from applications that are located in the /Application directory. Workaround to debug the application:

  1. move your application bundle generated by QtCreator into the /Application directory (the generated *.app file).

  2. create a symbolic link from the /Application/*.app directory to the build directory (ln -s /Application/MyFancyApp.app <MyFancyBuildDir>/)

Now you can launch and debug the app as usual using the Qt Creator.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 antoine
Solution 2 Sebastian