Skip to content

Commit

Permalink
Merge pull request opencv#14278 from mshabunin:fix-osx-camera-auth-rt
Browse files Browse the repository at this point in the history
* AVFoundation: Use runtime check for camera authorization
  • Loading branch information
mshabunin authored and alalek committed Apr 11, 2019
1 parent 64168fc commit 5cb0ede
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions modules/videoio/src/cap_avfoundation_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,27 @@ bool isOpened() const
NSAutoreleasePool *localpool = [[NSAutoreleasePool alloc] init];

#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusDenied)
if (@available(macOS 10.14, *))
{
fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' "
"command in same terminal to reset application authorization status, "
"either modify 'System Preferences -> Security & Privacy -> Camera' "
"settings for your application.\n");
[localpool drain];
return 0;
}
else if (status != AVAuthorizationStatusAuthorized)
{
fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status);
// TODO: doesn't work via ssh
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
// we do not wait for completion
[localpool drain];
return 0;
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusDenied)
{
fprintf(stderr, "OpenCV: camera access has been denied. Either run 'tccutil reset Camera' "
"command in same terminal to reset application authorization status, "
"either modify 'System Preferences -> Security & Privacy -> Camera' "
"settings for your application.\n");
[localpool drain];
return 0;
}
else if (status != AVAuthorizationStatusAuthorized)
{
fprintf(stderr, "OpenCV: not authorized to capture video (status %ld), requesting...\n", status);
// TODO: doesn't work via ssh
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL) { /* we don't care */}];
// we do not wait for completion
[localpool drain];
return 0;
}
}
#endif

Expand Down

0 comments on commit 5cb0ede

Please sign in to comment.