以下是我设置简单相机应用的代码
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)
}
}
}
}
这样可以正常工作,但会在调试窗口中抛出此消息
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)'
奇怪的是,当我尝试清理上面的代码时,它仍然有效但现在速度要慢得多(通过清理我的意思是把东西放在辅助函数中)。通过查看相关帖子,
Playing audio from URL give me this log error and stuck .(Swift)
AVPlayer is not playing in iOS 11
我唯一可以推断的是它有与IOS 11相关的内容。如何修复此错误?