|
@@ -54,17 +54,14 @@ class CustomCameraViewController: UIViewController {
|
|
|
|
|
|
|
|
|
var session: AVCaptureSession?
|
|
|
- var stillImageOutput:AVCaptureOutput{
|
|
|
- if #available(iOS 11.0, *) {
|
|
|
- return AVCapturePhotoOutput()
|
|
|
- } else {
|
|
|
- let stillImageOutput = AVCaptureStillImageOutput()
|
|
|
- stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
|
|
|
- return stillImageOutput
|
|
|
- }
|
|
|
+ var stillImageOutput:AVCaptureStillImageOutput{
|
|
|
+ let stillImageOutput = AVCaptureStillImageOutput()
|
|
|
+ stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
|
|
|
+ return stillImageOutput
|
|
|
}
|
|
|
-// var stillImageOutput: AVCaptureStillImageOutput?
|
|
|
-// var stillImageOutput: AVCapturePhotoOutput?
|
|
|
+
|
|
|
+ @available(iOS 11.0, *)
|
|
|
+ lazy var newStillImageOutput: AVCapturePhotoOutput = AVCapturePhotoOutput()
|
|
|
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
|
|
|
|
|
|
static var photoProcessCommit = MutableProperty<Photo?>(nil)
|
|
@@ -95,8 +92,12 @@ extension CustomCameraViewController{
|
|
|
session!.addInput(input)
|
|
|
|
|
|
if session!.canAddOutput(stillImageOutput) {
|
|
|
- session!.addOutput(stillImageOutput)
|
|
|
- session!.commitConfiguration()
|
|
|
+ if #available(iOS 11.0, *) {
|
|
|
+ session!.addOutput(newStillImageOutput)
|
|
|
+ }else{
|
|
|
+ session!.addOutput(stillImageOutput)
|
|
|
+ }
|
|
|
+
|
|
|
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: session!)
|
|
|
videoPreviewLayer!.videoGravity = AVLayerVideoGravity.resizeAspect
|
|
|
videoPreviewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
@@ -131,15 +132,13 @@ extension CustomCameraViewController{
|
|
|
if #available(iOS 11.0, *) {
|
|
|
let settings = AVCapturePhotoSettings()
|
|
|
settings.livePhotoVideoCodecType = .jpeg
|
|
|
- guard let `stillImageOutput` = stillImageOutput as? AVCapturePhotoOutput else{ return }
|
|
|
- stillImageOutput.capturePhoto(with: settings, delegate: self)
|
|
|
+
|
|
|
+
|
|
|
+ newStillImageOutput.capturePhoto(with: settings, delegate: self)
|
|
|
}else{
|
|
|
guard let connection = stillImageOutput.connection(with: AVMediaType.video) else {
|
|
|
return
|
|
|
}
|
|
|
- guard let `stillImageOutput` = stillImageOutput as? AVCaptureStillImageOutput else {
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
stillImageOutput.captureStillImageAsynchronously(from: connection, completionHandler: { [weak self](buffer, error) in
|
|
|
if let _ = error{
|