Skip to content

Commit

Permalink
- Fixes an issue where checking for camera permissions would cause a …
Browse files Browse the repository at this point in the history
…crash on macOS < 10.14.
  • Loading branch information
vonnieda committed Sep 10, 2020
1 parent e34ee54 commit db3a904
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions mac/platformcontext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,35 @@ of this software and associated documentation files (the "Software"), to deal
Context()
{
LOG(LOG_INFO, "Platform context created\n");
cameraPermissionReceived = 0;
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusAuthorized) {
NSLog(@"Already have camera permission");
cameraPermissionReceived = 1;
}
else {
NSLog(@"Requesting permission, bundle path for Info.plist: %@", [[NSBundle mainBundle] bundlePath]);
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
cameraPermissionReceived = 1;
} else {
cameraPermissionReceived = -1;
}
if (granted) {
NSLog(@"Permission granted");
} else {
NSLog(@"Failed to get permission");
if ([AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
cameraPermissionReceived = 0;
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusAuthorized) {
NSLog(@"Already have camera permission");
cameraPermissionReceived = 1;
}
else {
NSLog(@"Requesting permission, bundle path for Info.plist: %@", [[NSBundle mainBundle] bundlePath]);
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
cameraPermissionReceived = 1;
} else {
cameraPermissionReceived = -1;
}
if (granted) {
NSLog(@"Permission granted");
} else {
NSLog(@"Failed to get permission");
}
} ];
while (cameraPermissionReceived == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
} ];
while (cameraPermissionReceived == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
if (cameraPermissionReceived == 1) {
enumerateDevices();
}
}
if (cameraPermissionReceived == 1) {
else {
enumerateDevices();
}
}
Expand Down

0 comments on commit db3a904

Please sign in to comment.