Prechádzať zdrojové kódy

AVCaptureOutput protocol로 변수 선언시 AVCapturePhotoOutput connection을 생성하지 못하는 버그 수정

서용하 6 rokov pred
rodič
commit
fbd68c287a

+ 0 - 3
MCPlus.xcodeproj/project.pbxproj

@@ -453,7 +453,6 @@
 		129D1CB321CB62AD00A9D764 /* CallbackUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CallbackUtil.h; sourceTree = "<group>"; };
 		129D1CB421CB62AD00A9D764 /* CallbackUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CallbackUtil.m; sourceTree = "<group>"; };
 		129D1CE221CB7AF800A9D764 /* kunkuk_inhouse.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = kunkuk_inhouse.app; sourceTree = BUILT_PRODUCTS_DIR; };
-		12FD22531E28FE3000195209 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
 		1B4135BA1A2E52E0D69C7248 /* Pods-kunkuk.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-kunkuk.release.xcconfig"; path = "Pods/Target Support Files/Pods-kunkuk/Pods-kunkuk.release.xcconfig"; sourceTree = "<group>"; };
 		290A0CED2216461100BEC6C0 /* ExtensionCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionCollection.swift; sourceTree = "<group>"; };
 		290D82252235F1F70077B497 /* MCPlusTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCPlusTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1149,7 +1148,6 @@
 			hasScannedForEncodings = 0;
 			knownRegions = (
 				English,
-				en,
 				Base,
 				ko,
 			);
@@ -1907,7 +1905,6 @@
 		1219F74B1E2730C100469209 /* Localizable.strings */ = {
 			isa = PBXVariantGroup;
 			children = (
-				12FD22531E28FE3000195209 /* en */,
 				1299654121FB38D60078C49F /* ko */,
 			);
 			name = Localizable.strings;

+ 16 - 17
MCPlus/ViewControllers/CustomCameraViewController.swift

@@ -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{