iOS获取相机、麦克风权限及异步结果回调

info.plist添加权限申请

  • 相机权限
Privacy - Camera Usage Description
  • 麦克风权限
Privacy - Microphone Usage Description

引入AVFoundation

import AVFoundation

权限申请

  • 相机权限申请及结果回调
/// 获取相机权限
AVCaptureDevice.requestAccess(for: .video) { (granted) in
    /// 结果回调
}
  • 麦克风权限申请及结果回调
/// 获取麦克风权限
AVCaptureDevice.requestAccess(for: .audio) { (granted) in
    /// 结果回调
}