Commit 5cb0eded authored by Maksim Shabunin's avatar Maksim Shabunin Committed by Alexander Alekhin

Merge pull request #14278 from mshabunin:fix-osx-camera-auth-rt

* AVFoundation: Use runtime check for camera authorization
parent 64168fc2
...@@ -325,24 +325,27 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) { ...@@ -325,24 +325,27 @@ int CvCaptureCAM::startCaptureDevice(int cameraNum) {
NSAutoreleasePool *localpool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *localpool = [[NSAutoreleasePool alloc] init];
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (@available(macOS 10.14, *))
if (status == AVAuthorizationStatusDenied)
{ {
fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' " AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
"command in same terminal to reset application authorization status, " if (status == AVAuthorizationStatusDenied)
"either modify 'System Preferences -> Security & Privacy -> Camera' " {
"settings for your application.\n"); fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' "
[localpool drain]; "command in same terminal to reset application authorization status, "
return 0; "either modify 'System Preferences -> Security & Privacy -> Camera' "
} "settings for your application.\n");
else if (status != AVAuthorizationStatusAuthorized) [localpool drain];
{ return 0;
fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status); }
// TODO: doesn't work via ssh else if (status != AVAuthorizationStatusAuthorized)
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}]; {
// we do not wait for completion fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status);
[localpool drain]; // TODO: doesn't work via ssh
return 0; [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
// we do not wait for completion
[localpool drain];
return 0;
}
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment