Here is my code setting up a simple camera app
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let deviceSession = AVCaptureDeviceDiscoverySession(deviceTypes: [.builtInDualCamera, .builtInTelephotoCamera, .builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: .unspecified)
for device in (deviceSession?.devices)!{
if device.position == AVCaptureDevicePosition.front {
do {
currentDevice = device
let input = try AVCaptureDeviceInput(device: device)
if captureSession.canAddInput(input){
captureSession.addInput(input)
if captureSession.canAddOutput(photoOutput){
captureSession.addOutput(photoOutput)
}
if captureSession.canAddOutput(videoOutput){
captureSession.addOutput(videoOutput)
videoOutput.connection(withMediaType: AVMediaTypeVideo).isVideoMirrored = true
}
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.connection.videoOrientation = .portrait //Change orientation
cameraView.layer.addSublayer(previewLayer)
cameraView.addSubview(takePictureButton)
cameraView.addSubview(takeVideoButton)
cameraView.addSubview(saveVideoButton)
previewLayer.position = CGPoint(x: self.view.center.x, y: self.view.center.y)
previewLayer.bounds = CGRect(x: 100, y: 150, width: self.view.frame.width, height: self.view.frame.height)
}
captureSession.startRunning()
} catch let avError {
print(avError)
}
}
}
}
This works fine, but throws this message in the debug window
2018-02-26 20:12:27.699481-0800 FACS[1063:425226] [] <<<<
AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>>
-[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl
outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device
discovery mode to DiscoveryMode_None (client: FACS)
2018-02-26 20:12:27.774719-0800 FACS[1063:425226] [framework]
CUICatalog: Invalid asset name supplied: '(null)'
The strange part is that when I try to clean up the code above, it still works but now is much slower (by cleanup I mean put things in helper functions). By looking at related posts,
Playing audio from URL give me this log error and stuck .(Swift)
AVPlayer is not playing in iOS 11
the only thing I can deduce is that it has something related to IOS 11. How do I fix this error?