在iOS上捕获照片时出现随机错误

Che*_*rif 3 ios avcapture avcapturesession swift

我正在尝试捕捉图像:

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)
          }
     })
}
Run Code Online (Sandbox Code Playgroud)

它大多数时候都很完美!

但有时我在调用时遇到错误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)}
Run Code Online (Sandbox Code Playgroud)

我只是想预料会发生这个错误.我尝试过测试videoConnection.enabled,videoConnection.active但两者似乎都与错误无关......

在拍摄照片之前,我需要检查以确保一切正常?

ast*_*mme 5

我也收到了与您相同的错误消息.经过大量调试后,我意识到在拍摄照片之前我无意中停止了拍摄会话.仔细检查.running你的财产AVCaptureSessiontrue.