我想在这里捕捉图像:
var stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
[...]
if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) {
videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
println("enabled = \(videoConnection.enabled)") //enabled = true
println("active = \(videoConnection.active)") //active = true
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {
(sampleBuffer, error) in
if error != nil {
println(error)
}
})
}
它在大多数情况下都能完美运行!
但有时我在调用时遇到错误captureStillImageAsynchronouslyFromConnection
:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn't be completed."
UserInfo=0x14682110 {NSLocalizedDescription=The operation couldn't be completed.,
NSUnderlyingError=0x1676be30 "The operation couldn't be completed.
(OSStatus error -16400.)",
NSLocalizedFailureReason=An unknown error has occured (-16400)}
我只是想预计会发生此错误。我尝试过测试videoConnection.enabled
,videoConnection.active
但两者似乎都与错误无关......
在拍摄照片之前我需要检查什么以确保一切正常?