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

China☆狼群 提交于 2020-07-09 07:14:36

问题


I want to create a camera calibration application with opencv for a university course. I have created a command line tool application on macOS High Sierra. Unfortunately it came without an info.plist file. My application crashes with the following error message:

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

I have already tried adding a info.plist file and setting it in the applications' General tab. I have also added the NSCameraUsageDescription key and string. Unfortunately my application keeps on crashing due to the exact same error.


回答1:


You can embed an Info.plist in your binary by setting Create Info.plist Section in Binary and setting a path to your Info.plist file in Xcode > Target > Build Settings > Packaging (changes marked in bold):

Your Info.plist might look like 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>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: when running in the debugger in Xcode (11.2.1/Catalina 10.15.1) I still get a privacy exception, however the plist is embedded in the binary. I guess this is an Xcode bug. Dropping an Info.plist into the Products directory works around this, although you seem to have to re-authorise microphone/camera usage every time the binary is modified.



来源:https://stackoverflow.com/questions/55518922/missing-info-plist-file-for-c-command-line-tool-application-within-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!