ios - AVCaptureDevice.requestAccess() 崩溃

标签 ios xcode avfoundation xcode8-beta2

我使用 Swift 3.0 和 Xcode 8 Beta 2 创建了一个 iOS 单 View 应用程序。我正在链接 AVFoundation.framework

这是我的 View Controller 代码:

import UIKit
import AVFoundation

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == .notDetermined {
      AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) in
        if granted {
          print("granted")
        }
        else {
          print("not granted")
        }
      })
    }
  }
}

当我在我的设备上运行它时,应用程序在执行 AVCapture.requestAccess 行后崩溃(未执行完成处理程序,也没有抛出异常)。

控制台中唯一的东西是:

2016-07-15 14:55:44.621819 testpp[2261:912051] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-07-15 14:55:44.626012 testpp[2261:912051] [MC] Reading from public effective user settings.
2016-07-15 14:55:59.284610 testpp[2261:912085] [access] <private>

我做错了什么吗?

最佳答案

请确保在请求相机访问权限时为 Info.plist 文件中的 Privacy - Camera Usage Description 键设置值。

关于ios - AVCaptureDevice.requestAccess() 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38403387/

相关文章:

ios - 无法从 Facebook 帐户工具包获取短信代码

ios - AVAssetWriter startSessionAtSourceTime : Cannot call method when status is 0

objective-c - AVCam 项目在 iPad 上崩溃

ios - 如何设计自定义导航栏

ios - UITextField 的文本插入?

iOS7 PhoneGap 使用 ZBar 扫描仪后卡住

swift - 删除 double 的小数部分而不将其快速转换为 Int

c++ - XCode 如何使用 LLDB?

ios - 点击后隐藏 View

ios - AVPlayer 永远无法播放