From 520e3afeac788c6d243afb6dcf395885fa142e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= Date: Fri, 21 Jul 2023 13:23:11 -0400 Subject: [PATCH] fix(CameraCaptureUI): [iOS] Adjust camera capture for recent iOS builds (cherry picked from commit 8b34d8093bdc950c4f8e283a0b36f94f48505504) --- .../Media/Capture/CameraCaptureUI.iOS.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Uno.UWP/Media/Capture/CameraCaptureUI.iOS.cs b/src/Uno.UWP/Media/Capture/CameraCaptureUI.iOS.cs index 7e3b9e3554a5..ee2a38ba7430 100644 --- a/src/Uno.UWP/Media/Capture/CameraCaptureUI.iOS.cs +++ b/src/Uno.UWP/Media/Capture/CameraCaptureUI.iOS.cs @@ -39,7 +39,13 @@ private async Task CaptureFile(CancellationToken ct, CameraCaptureU break; case CameraCaptureUIMode.Video: +#pragma warning disable CA1416 // UTType.Image, UTType.Movie is supported on ios version 14 and above + picker.MediaTypes = new string[] { MobileCoreServices.UTType.Movie }; +#pragma warning restore CA1416 picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; + + await ValidateCameraAccess(); + await ValidateMicrophoneAccess(); break; } } @@ -108,6 +114,34 @@ private static bool IsUsageKeyDefined(string usageKey) : true; } + private async Task ValidateMicrophoneAccess() + { + if (!IsUsageKeyDefined("NSMicrophoneUsageDescription")) + { + throw new InvalidOperationException("Info.plist must define NSMicrophoneUsageDescription"); + } + + var isAllowed = (await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVAuthorizationMediaType.Audio)); + if (!isAllowed) + { + throw new UnauthorizedAccessException(); + } + } + + private async Task ValidateCameraAccess() + { + if (!IsUsageKeyDefined("NSCameraUsageDescription")) + { + throw new InvalidOperationException("Info.plist must define NSCameraUsageDescription"); + } + + var isAllowed = (await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVAuthorizationMediaType.Video)); + if (!isAllowed) + { + throw new UnauthorizedAccessException(); + } + } + private async Task ValidatePhotoLibraryAccess() { if (!IsUsageKeyDefined("NSPhotoLibraryUsageDescription"))