答案 0 :(得分:-1)
在iOS上请求媒体捕获的授权: https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios
配置应用程序的Info.plist文件:
如果您的应用程序使用设备相机,请在应用程序的Info.plist文件中包含“ NSCameraUsageDescription”键。
验证并请求捕获授权:
override func viewDidLoad() {
super.viewDidLoad()
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized: // The user has previously granted access to the camera.
.....
case .notDetermined: // The user has not yet been asked for camera access.
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
.....
}
}
case .denied: // The user has previously denied access.
return
case .restricted: // The user can't grant access due to restrictions.
return
}
}