6
2

More than 3 years have passed since last update.

【Unity】iOSのカメラ使用時にiOS実機ビルドでクラッシュする時の対処法

Posted at

UnityでiOSのカメラを使う際は、WebCamTextureクラスを使います。
以下のショートコードでプラットフォームを越えてカメラ情報を取得することが出来るので本当にUnityは便利です。

WebCamTest.cs
[SerializeField] RawImage _rawImage;
void Start()
{
    var webCamTexture = new WebCamTexture();
    _rawImage.texture = webCamTexture;
    webCamTexture.Play();
}

UnityEditor上で実行する上では問題なく動くと思います。
しかし、XcodeでiOS端末で実行すると、Xcodeのコンソールで以下のエラーを吐いて落ちる時があります。

本記事はその対処法備忘録です。

[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.

Camera Usage Descriptionへの入力必須

PlayerSettings > OtherSettings > Camera Usage Description
この項目に何かしらの文字列を入れる必要があります。

Xcodeのinfo.plistのPrivacy - Camera Usage Descriptionに追加される事になります。

Camera Usage Descriptionを設定してiOS実機ビルドするとクラッシュしなくなると思います。


ちなみに、Camera Usage Descriptionはカメラ使用時の許可ダイアログ内の説明文で使用されます。

環境

  • iPhone6s iOS 13.6
  • Unity2019.4.4f1
  • Xcode 11.6
6
2
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
6
2