您可以使用以下代码执行相同的操作:
if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) == AVAuthorizationStatus.Authorized { // Already Authorized} else { AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted: Bool) -> Void in if granted == true {// User granted } else {// User rejected } })}注意:
- 确保
AVFoundation
在构建阶段的“链接二进制”部分中添加框架 - 您应该
import AVFoundation
在课堂上写一些用于导入的内容AVFoundation
SWIFT 3
if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == AVAuthorizationStatus.authorized { // Already Authorized} else { AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) -> Void in if granted == true { // User granted } else { // User Rejected } })}斯威夫特4
if AVCaptureDevice.authorizationStatus(for: .video) == .authorized { //already authorized} else { AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in if granted { //access allowed } else { //access denied } })}


