相机权限:
AVCaptureDevice.requestAccess(for: .video) { result in
DispatchQueue.main.async {
if result == true {
//允许访问相机
}else {
//不允许访问相机
}
}
}
相册权限:
PHPhotoLibrary.requestAuthorization { status in
DispatchQueue.main.async {
let sta: PHAuthorizationStatus = status as PHAuthorizationStatus
switch sta {
case .authorized:
//允许访问所有的相册
case .limited:
//访问部分相册受限
default:
//
}
}
}
麦克风
AVCaptureDevice.requestAccess(for: .audio) { result in
if result == true {
//允许访问麦克风
}else {
//不允许访问麦克风
}
}
plist文件:
Privacy - Camera Usage Description 相机
Privacy - Photo Library Additions Usage Description 相册
Privacy - Photo Library Usage Description 相册
Privacy - Microphone Usage Description 麦克风