mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
[MacOS] Ask user for permission to access microphone
This is required for MacOS 10.14 and later. This also requires an explanation why access is required in the apps Info.plist. Hence added custom Info.plist templates for each app.
This commit is contained in:
committed by
Klaus Basan
parent
61adfefa7a
commit
5f00747d19
@@ -70,6 +70,10 @@ SOURCES += *.cpp \
|
||||
$$PWD/test/*.cpp \
|
||||
$$PWD/weather/*.cpp
|
||||
|
||||
macx {
|
||||
HEADERS += $$PWD/macos/microphoneaccess.h
|
||||
OBJECTIVE_SOURCES += $$PWD/macos/microphoneaccess.mm
|
||||
}
|
||||
|
||||
INCLUDEPATH *= $$EXTERNALSROOT/common/include/crashpad
|
||||
INCLUDEPATH *= $$EXTERNALSROOT/common/include/crashpad/mini_chromium
|
||||
@@ -87,7 +91,7 @@ msvc {
|
||||
CONFIG(debug, debug|release): LIBS *= -lclientd -lutild -lbased -lRpcrt4 -lAdvapi32
|
||||
CONFIG(release, debug|release): LIBS *= -lclient -lutil -lbase -lRpcrt4 -lAdvapi32
|
||||
}
|
||||
macx: LIBS += -lclient -lutil -lbase -lbsm -framework Security -framework CoreFoundation -framework ApplicationServices -framework Foundation
|
||||
macx: LIBS += -lclient -lutil -lbase -lbsm -framework AVFoundation -framework Security -framework CoreFoundation -framework ApplicationServices -framework Foundation
|
||||
unix:!macx: LIBS *= -lclient -lutil -lbase
|
||||
|
||||
DESTDIR = $$DestRoot/lib
|
||||
|
||||
48
src/blackmisc/macos/microphoneaccess.h
Normal file
48
src/blackmisc/macos/microphoneaccess.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AUDIOACCESSREQUEST_H
|
||||
#define BLACKMISC_AUDIOACCESSREQUEST_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
//! Wrapper around MacOS 10.14 AVCaptureDevice AVCaptureDevice authorization
|
||||
class BLACKMISC_EXPORT CMacOSMicrophoneAccess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//! Authorization status
|
||||
enum AuthorizationStatus
|
||||
{
|
||||
Authorized,
|
||||
Denied,
|
||||
NotDetermined
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
CMacOSMicrophoneAccess(QObject *parent = nullptr);
|
||||
|
||||
//! Request access
|
||||
void requestAccess();
|
||||
|
||||
//! Get current authorization status
|
||||
AuthorizationStatus getAuthorizationStatus();
|
||||
|
||||
signals:
|
||||
//! User has answered the permission request popup
|
||||
void permissionRequestAnswered(bool granted);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
62
src/blackmisc/macos/microphoneaccess.mm
Normal file
62
src/blackmisc/macos/microphoneaccess.mm
Normal file
@@ -0,0 +1,62 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "microphoneaccess.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
//#ifdef Q_OS_MAC
|
||||
|
||||
BlackMisc::CMacOSMicrophoneAccess::CMacOSMicrophoneAccess(QObject *parent) :
|
||||
QObject(parent)
|
||||
{ }
|
||||
|
||||
void CMacOSMicrophoneAccess::requestAccess()
|
||||
{
|
||||
if (@available(macOS 10.14, *))
|
||||
{
|
||||
NSString *mediaType = AVMediaTypeAudio;
|
||||
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted)
|
||||
{
|
||||
emit permissionRequestAnswered(granted);
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
emit permissionRequestAnswered(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CMacOSMicrophoneAccess::AuthorizationStatus CMacOSMicrophoneAccess::getAuthorizationStatus()
|
||||
{
|
||||
if (@available(macOS 10.14, *))
|
||||
{
|
||||
NSString *mediaType = AVMediaTypeAudio;
|
||||
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
|
||||
if(authStatus == AVAuthorizationStatusAuthorized)
|
||||
{
|
||||
return AuthorizationStatus::Authorized;
|
||||
}
|
||||
else if(authStatus == AVAuthorizationStatusNotDetermined)
|
||||
{
|
||||
return AuthorizationStatus::NotDetermined;
|
||||
}
|
||||
return AuthorizationStatus::Denied;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuthorizationStatus::Authorized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user