@@ -45,30 +45,35 @@ of this software and associated documentation files (the "Software"), to deal
45
45
Context()
46
46
{
47
47
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 ));
65
70
}
66
- } ];
67
- while (cameraPermissionReceived == 0 ) {
68
- std::this_thread::sleep_for ( std::chrono::milliseconds ( 200 ) );
71
+ }
72
+ if (cameraPermissionReceived == 1 ) {
73
+ enumerateDevices ( );
69
74
}
70
75
}
71
- if (cameraPermissionReceived == 1 ) {
76
+ else {
72
77
enumerateDevices ();
73
78
}
74
79
}
0 commit comments