Skip to content

Commit db3a904

Browse files
committed
- Fixes an issue where checking for camera permissions would cause a crash on macOS < 10.14.
1 parent e34ee54 commit db3a904

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

mac/platformcontext.mm

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,35 @@ of this software and associated documentation files (the "Software"), to deal
4545
Context()
4646
{
4747
LOG(LOG_INFO, "Platform context created\n");
48-
cameraPermissionReceived = 0;
49-
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusAuthorized) {
50-
NSLog(@"Already have camera permission");
51-
cameraPermissionReceived = 1;
52-
}
53-
else {
54-
NSLog(@"Requesting permission, bundle path for Info.plist: %@", [[NSBundle mainBundle] bundlePath]);
55-
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
56-
if (granted) {
57-
cameraPermissionReceived = 1;
58-
} else {
59-
cameraPermissionReceived = -1;
60-
}
61-
if (granted) {
62-
NSLog(@"Permission granted");
63-
} else {
64-
NSLog(@"Failed to get permission");
48+
if ([AVCaptureDevice respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
49+
cameraPermissionReceived = 0;
50+
if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusAuthorized) {
51+
NSLog(@"Already have camera permission");
52+
cameraPermissionReceived = 1;
53+
}
54+
else {
55+
NSLog(@"Requesting permission, bundle path for Info.plist: %@", [[NSBundle mainBundle] bundlePath]);
56+
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
57+
if (granted) {
58+
cameraPermissionReceived = 1;
59+
} else {
60+
cameraPermissionReceived = -1;
61+
}
62+
if (granted) {
63+
NSLog(@"Permission granted");
64+
} else {
65+
NSLog(@"Failed to get permission");
66+
}
67+
} ];
68+
while (cameraPermissionReceived == 0) {
69+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
6570
}
66-
} ];
67-
while (cameraPermissionReceived == 0) {
68-
std::this_thread::sleep_for(std::chrono::milliseconds(200));
71+
}
72+
if (cameraPermissionReceived == 1) {
73+
enumerateDevices();
6974
}
7075
}
71-
if (cameraPermissionReceived == 1) {
76+
else {
7277
enumerateDevices();
7378
}
7479
}

0 commit comments

Comments
 (0)