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