Xcode 中缺少 C++ 命令行工具应用程序的 info.plist 文件

Missing info.plist file for C++ command line tool application within Xcode

我想用 opencv 创建一个用于大学课程的相机校准应用程序。我在 macOS High Sierra 上创建了一个命令行工具应用程序。不幸的是,它没有 info.plist 文件。我的应用程序崩溃并显示以下错误消息:

CameraCalibration[2314:193066] [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. Program ended with exit code: 9

我已经尝试添加 info.plist 文件并在应用程序的“常规”选项卡中进行设置。我还添加了 NSCameraUsageDescription 键和字符串。不幸的是,由于完全相同的错误,我的应用程序不断崩溃。

您可以通过设置 Create Info.plist Section in Binary 并在 Xcode > Target > Build Settings > Packaging 中设置您的 Info.plist 文件的路径(更改以粗体标记)将 Info.plist 嵌入您的二进制文件中:

您的 Info.plist 可能如下所示:

<?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>CFBundleIdentifier</key>
    <string>com.mycorp.myapp</string>
    <key>CFBundleName</key>
    <string>My App</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>record from the microphone</string>
    <key>NSCameraUsageDescription</key>
    <string>record from the camera</string>
</dict>
</plist>

N.B:当 运行 在 Xcode (11.2.1/Catalina 10.15.1) 中的调试器中时,我仍然得到一个隐私例外,但是 plist 嵌入在二进制文件中。我想这是一个 Xcode 错误。将 Info.plist 放入 Products 目录可以解决这个问题,尽管每次修改二进制文件时您似乎都必须重新授权 microphone/camera 使用。