官方文档大于一切
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos?language=objc
使用Authorization
的authorizationStatusForMediaType
即可获取权限
/*!
@method authorizationStatusForMediaType:
@abstract
Returns the client's authorization status for accessing the underlying hardware that supports a given media type.
@param mediaType
The media type, either AVMediaTypeVideo or AVMediaTypeAudio
@result
The authorization status of the client
@discussion
This method returns the AVAuthorizationStatus of the client for accessing the underlying hardware supporting the media type. Media type constants are defined in AVMediaFormat.h. If any media type other than AVMediaTypeVideo or AVMediaTypeAudio is supplied, an NSInvalidArgumentException will be thrown. If the status is AVAuthorizationStatusNotDetermined, you may use the +requestAccessForMediaType:completionHandler: method to request access by prompting the user.
*/
+ (AVAuthorizationStatus)authorizationStatusForMediaType:(AVMediaType)mediaType API_AVAILABLE(macos(10.14), ios(7.0));
处理代码示例:
AVAuthorizationStatus authorState = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
if (authorState == AVAuthorizationStatusRestricted ||authorState == AVAuthorizationStatusDenied) {
NSAlert* alert