xcode AVCaptureDevice.requestAccess() 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38403387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AVCaptureDevice.requestAccess() crash
提问by RobertJoseph
I created an iOS single view application using Swift 3.0 and Xcode 8 Beta 2. I am linking with the AVFoundation.framework.
我使用 Swift 3.0 和 Xcode 8 Beta 2 创建了一个 iOS 单视图应用程序。我正在与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.requestAccessline (the completion handler is not executed and no exceptions are thrown).
当我在我的设备上运行它时,应用程序在执行该AVCapture.requestAccess行后崩溃(未执行完成处理程序,也没有抛出异常)。
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?
难道我做错了什么?
回答by Jonas W
Make sure you set a value for the Privacy - Camera Usage Descriptionkey in your Info.plistfile when requesting camera access.
确保在请求访问相机时为文件中的Privacy - Camera Usage Description密钥设置一个值Info.plist。
回答by TBD


Input the permissions you need to the info.plist
在 info.plist 中输入你需要的权限

