mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 16:08:39 -05:00
Merge pull request #1824 from srcejon/fix_1819
Request authorization for access to camera and microphone on Mac
This commit is contained in:
commit
e83d974443
@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.13.0)
|
|||||||
|
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||||
|
|
||||||
project(sdrangel)
|
if(APPLE)
|
||||||
|
project(sdrangel LANGUAGES CXX OBJCXX)
|
||||||
|
else()
|
||||||
|
project(sdrangel)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
|
||||||
|
|
||||||
@ -911,6 +915,7 @@ target_link_libraries(sdrangelbench
|
|||||||
sdrbench
|
sdrbench
|
||||||
logging
|
logging
|
||||||
)
|
)
|
||||||
|
|
||||||
############ build sdrangel gui ################
|
############ build sdrangel gui ################
|
||||||
if (BUILD_GUI)
|
if (BUILD_GUI)
|
||||||
set(sdrangel_SOURCES
|
set(sdrangel_SOURCES
|
||||||
@ -918,7 +923,9 @@ if (BUILD_GUI)
|
|||||||
sdrgui/resources/sdrangel.rc
|
sdrgui/resources/sdrangel.rc
|
||||||
settings/settings.qrc
|
settings/settings.qrc
|
||||||
)
|
)
|
||||||
|
if(APPLE)
|
||||||
|
set(sdrangel_SOURCES ${sdrangel_SOURCES} mac/auth.mm)
|
||||||
|
endif()
|
||||||
if(ANDROID AND NOT ENABLE_QT6)
|
if(ANDROID AND NOT ENABLE_QT6)
|
||||||
add_library(${CMAKE_PROJECT_NAME} SHARED ${sdrangel_SOURCES})
|
add_library(${CMAKE_PROJECT_NAME} SHARED ${sdrangel_SOURCES})
|
||||||
elseif(ANDROID)
|
elseif(ANDROID)
|
||||||
@ -970,7 +977,10 @@ if (BUILD_GUI)
|
|||||||
sdrbase
|
sdrbase
|
||||||
sdrgui
|
sdrgui
|
||||||
logging
|
logging
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
if(APPLE)
|
||||||
|
target_link_libraries(${CMAKE_PROJECT_NAME} "-framework AVFoundation" objc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
@ -220,6 +220,12 @@ int main(int argc, char* argv[])
|
|||||||
sfc.setVersion(3, 3);
|
sfc.setVersion(3, 3);
|
||||||
sfc.setProfile(QSurfaceFormat::CoreProfile);
|
sfc.setProfile(QSurfaceFormat::CoreProfile);
|
||||||
QSurfaceFormat::setDefaultFormat(sfc);
|
QSurfaceFormat::setDefaultFormat(sfc);
|
||||||
|
|
||||||
|
// Request authorization for access to camera and microphone (mac/auth.mm)
|
||||||
|
extern int authCameraAndMic();
|
||||||
|
if (authCameraAndMic() < 0) {
|
||||||
|
qWarning("Failed to authorize access to camera and microphone. Enable access in System Settings > Privacy & Security");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
35
mac/auth.mm
Normal file
35
mac/auth.mm
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user