Skip to content

Commit

Permalink
fix(CameraCaptureUI): [iOS] Adjust camera capture for recent iOS builds
Browse files Browse the repository at this point in the history
(cherry picked from commit 8b34d80)
  • Loading branch information
jeromelaban authored and mergify[bot] committed Jul 23, 2023
1 parent 59276d9 commit 520e3af
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Uno.UWP/Media/Capture/CameraCaptureUI.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ private async Task<StorageFile> 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;
}
}
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 520e3af

Please sign in to comment.