0
我正在用相機的自定義視圖構建自定義相機應用程序。在ViewWillAppear部分中添加以下代碼,我在我添加星星的區域中出現以下錯誤: 二元運算符'!='不能應用於類型爲'Bool'和'NilLiteralConvertible'的操作數在swift 2.0中構建自定義相機應用程序時的錯誤
任何幫助非常感謝。
captureSession = AVCaptureSession()
captureSession.sessionPreset = AVCaptureSessionPreset1920x1080
let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var error : NSError?
var input: AVCaptureDeviceInput!
do {
input = try AVCaptureDeviceInput(device: backCamera)
} catch let error1 as NSError {
error = error1
input = nil
}
if error == nil && captureSession.canAddInput(input) != nil { *********
captureSession.addInput(input)
stillImageOutPut = AVCaptureStillImageOutput()
stillImageOutPut.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
if (captureSession.canAddOutput(stillImageOutPut) != nil){
captureSession.addOutput(stillImageOutPut)
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspect
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
cameraView.layer.addSublayer(previewLayer)
captureSession.startRunning()
}
}