所以我使用AVFoundation制作相机,但由于某些原因我在拍摄时不断出现此错误,大部分时间都会导致手机失去与Xcode的连接并导致应用程序崩溃,也用它来裁剪图像并得到同样的错误。 有人能告诉我为什么会出现这个错误吗?
Communications error: <OS_xpc_error: <error: 0x19b14ca80> { count = 1,
contents = "XPCErrorDescription" => <string: 0x19b14ce78> {
length = 22, contents = "Connection interrupted" } }>
以下是捕获的代码:
public func capturePictureWithCompletition(imageCompletition: (UIImage?, NSError?) -> Void) {
var blockHandler = { (imageDataSampleBuffer: CMSampleBuffer?, error: NSError?) -> Void in
if let imageDataSampleBuffer = imageDataSampleBuffer {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
let image = UIImage(data: imageData)
imageCompletition(image?.normalizedImages, nil)
} else {
imageCompletition(nil, error)
}
}
if self.cameraIsSetup {
if self.cameraOutputMode == .StillImage {
if let stillImageOutput = self.stillImageOutput {
let connection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo)
stillImageOutput.captureStillImageAsynchronouslyFromConnection(connection, completionHandler: blockHandler)
}
}
}
}