简体   繁体   中英

AVCaptureDevice.requestAccess() crash

I created an iOS single view application using Swift 3.0 and Xcode 8 Beta 2. I am linking with the AVFoundation.framework .

This is my view controller code:

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")
        }
      })
    }
  }
}

When I run this on my device the app crashes after executing the AVCapture.requestAccess line (the completion handler is not executed and no exceptions are thrown).

The only thing in the Console is:

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>

Am I doing something wrong?

请求在访问摄像机时,确保为Info.plist文件中的“ Privacy - Camera Usage Description键设置了值。

在此输入图像描述

Input the permissions you need to the info.plist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM