-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1824 from srcejon/fix_1819
Request authorization for access to camera and microphone on Mac
- Loading branch information
Showing
3 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Request permission.authorization to use camera and microphone | ||
// From: https://developer.apple.com/documentation/bundleresources/information_property_list/protected_resources/requesting_authorization_for_media_capture_on_macos?language=objc | ||
|
||
#include <AVFoundation/AVFoundation.h> | ||
|
||
// Returns: | ||
// 1 - if permission granted, | ||
// 0 - if pending, | ||
// -1 - if not granted. | ||
int authCameraAndMic() | ||
{ | ||
// Request permission to access the camera and microphone. | ||
switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) | ||
{ | ||
case AVAuthorizationStatusAuthorized: | ||
// The user has previously granted access to the camera. | ||
return 1; | ||
case AVAuthorizationStatusNotDetermined: | ||
{ | ||
// The app hasn't yet asked the user for camera access. | ||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { | ||
if (granted) { | ||
} | ||
}]; | ||
return 0; | ||
} | ||
case AVAuthorizationStatusDenied: | ||
// The user has previously denied access. | ||
return -1; | ||
case AVAuthorizationStatusRestricted: | ||
// The user can't grant access due to restrictions. | ||
return -1; | ||
} | ||
} | ||
|