4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XcodeでOpenCV4が使えなくなった解決策(カメラのアクセスを許可する方法)

Posted at

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個くらいを全てドラッグ&ドロップする

image.png

パスの設定

Build Settings の Header Search Paths に /usr/local/Cellar/opencv/4.0.1/include (recursive)とする

image.png

解決策

以下を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>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のフォルダなので注意!
image.png

こんな感じになっていればOK。
image.png

最初に起動するときは、許可をする必要があります。
image.png

参考

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?