2015-09-11 65 views
3

我想這裏的照片拍攝圖像時:隨機誤差捕捉iOS上

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.enabledvideoConnection.active進行測試,但是兩者似乎都與錯誤無關...

在捕獲照片之前,我需要檢查以確保一切正常嗎?

+0

也經過很多調試。我解決了這個問題:http://stackoverflow.com/a/42691502/7084347 –

回答

5

我也收到了你所做的同樣的錯誤信息。經過很多調試之後,我意識到在拍攝照片之前我無意中停止了拍攝。請仔細檢查您的AVCaptureSession.running財產是否爲true