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?
Make sure you set a value for the Privacy - Camera Usage Description
key in your Info.plist
file when requesting camera access.