我使用
Swift 3.0和Xcode 8 Beta 2创建了一个iOS单视图应用程序.我正在使用AVFoundation.framework进行链接.
这是我的视图控制器代码:
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文件中的“隐私 – 摄像机使用说明”键设置了值.