8

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
CoderOfTheForce
  • 359
  • 7
  • 22

1 Answers1

11

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):

Xcode target Info.plist settings

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.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • 3
    Thanks for the Info.plist in Products directory tip! – ibash Jul 02 '20 at 21:09
  • That didn't work for me ; i can't read the plist info fwith swift – A.HADDAD Sep 10 '21 at 07:44
  • This question isn't about reading your own plist - can you start a new question? – Rhythmic Fistman Sep 10 '21 at 08:55
  • I am seeking a solution to add an Info.plist for an already created executable, i.e. without the use of Xcode. I suspect the `ld` cmd can do that. Any idea how, precisely? Huh, this q is specifically about use _with_ Xcode. I'll try to find another one. – Thomas Tempelmann Nov 07 '22 at 19:44
  • the --sectcreate args mentioned here seem to be what you're looking for: https://github.com/xamarin/xamarin-macios/issues/13795#issuecomment-1021358936 – Rhythmic Fistman Nov 11 '22 at 09:09