Xcodeをアップデートしてからか、OpenCV4にしてからか、下記のエラーが出て使えなくなってしまいました。
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.
Xcodeにカメラを起動を許可するように設定してあげる必要があるようです。
動作環境
macOS Mojave (10.14.4)
Xcode (10.2.1)
OpenCV (4.0.1)
Xcodeでの設定
一応確認ですが、XcodeでOpenCVを使うために、以下のように設定してあります。
ライブラリの追加
Build Phases の Link Binary With Libraries に/usr/local/Cellar/opencv/4.0.1/lib/
(このパスはbrew info opencv
等で確認)にあるdylibファイル44個くらいを全てドラッグ&ドロップする
パスの設定
Build Settings の Header Search Paths に /usr/local/Cellar/opencv/4.0.1/include
(recursive)とする
解決策
以下を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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSCameraUsageDescription</key>
<string>This requires access to your camera.</string>
<key>NSAppleEventsUsageDescription</key>
<string>Test</string>
<key>NSMicrophoneUsageDescription</key>
<string>Test</string>
</dict>
</plist>
これをProductsフォルダ内に置きます。実行ファイルを右クリックしてShow in Finderとすることで、そのフォルダを開くことができます。
これはプロジェクト内のフォルダではなく、LibraryにあるXcodeのフォルダなので注意!
参考