[Interest] Mac OS - AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo crashes application

Nuno Santos nunosantos at imaginando.pt
Fri Jan 10 10:16:39 CET 2020


Roland,

After spending more than 4 hours googling and searching for others examples and realising I was not doing anything wrong I have stumbled with a detail that was causing the crash.

I was codesiging it with: codesign BUNDLE.app -s \"Developer ID Application: Acme Inc. (XPTO)\" --options "runtime"

Removing the —options “runtime” did the trick. The documentation says:

runtime  On macOS versions >= 10.14.0, opts signed processes into a hard-
              ened runtime environment which includes runtime code signing
              enforcement, library validation, hard, kill, and debugging
              restrictions.  These restrictions can be selectively relaxed via
              entitlements. Note: macOS versions older than 10.14.0 ignore the
              presence of this flag in the code signature.

But I still don’t understand why it was crashing with this option.

The app was not crashing on the computer that was built and signed but as soon it ran on another computer it would crash with the __CRASHING_DUE_TO_PRIVACY_VIOLATION__ reason.

This was a very tricky one!

Thanks for your reply.

Best regards,

Nuno

> On 10 Jan 2020, at 09:05, Roland Winklmeier <roland.m.winklmeier at gmail.com> wrote:
> 
> Am Do., 9. Jan. 2020 um 18:05 Uhr schrieb Nuno Santos <nunosantos at imaginando.pt <mailto:nunosantos at imaginando.pt>>:
> Hi,
> 
> I’m trying to setup camera usage permission request for 10.14 (Mojave) and 10.15 (Catalina). I have added the camera and microphone permissions in the Info.plist as in below:
> 
> <key>NSCameraUsageDescription</key>
> <string>This application uses the video camera to communicate with another endpoint.</string>
> <key>NSMicrophoneUsageDescription</key>
> <string>This application uses the microphone input to communicate with another endpoint.</string>
> 
> But the app keeps crashing as soon as the permission code below is called when it should prompt for permissions:
> 
> void CameraManager::requestCameraUsagePermission()
> {
>     switch([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
>     {
>         case AVAuthorizationStatusAuthorized:
>             _isCameraUsageAllowed = true;
>             break;
>         case AVAuthorizationStatusNotDetermined:
>             // crashes as soon this line is called
>             [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
>             {
>             }];
>             break;
>         case AVAuthorizationStatusRestricted:
>             _isCameraUsageAllowed = false;
>             break;
>         case AVAuthorizationStatusDenied:
>             _isCameraUsageAllowed = false;
>     }
> }
> 
> For me the following snippet works fine:
> 
> if (@available(macOS 10.14, *))
> {
>     NSString *mediaType = AVMediaTypeAudio;
>     [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler: ^ (BOOL granted)
>                     {
>                         emit permissionRequestAnswered(granted);
>                     }];
> }
> else
> {
>     emit permissionRequestAnswered(true);
> }
> 
> Are you running the sample on macOS 10.14 or higher? Other than that, maybe info.plist in the build directory is not correct or something?
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200110/f07e7da5/attachment.html>


More information about the Interest mailing list