     
     open class func checkCameraPermission(_ handler: @escaping (_ granted: Bool) -> Void) {
         func hasCameraPermission() -> Bool {
+            #if swift(>=4.0)
             return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
+            #else
+            return AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == .authorized
+            #endif
         }
         
         func needsToRequestCameraPermission() -> Bool {
+            #if swift(>=4.0)
             return AVCaptureDevice.authorizationStatus(for: .video) == .notDetermined
-        }
-        
+            #else
+            return AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == .notDetermined
+            #endif
+        }
+        
+        #if swift(>=4.0)
         hasCameraPermission() ? handler(true) : (needsToRequestCameraPermission() ?
             AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in
                 DispatchQueue.main.async(execute: { () -> Void in
                     hasCameraPermission() ? handler(true) : handler(false)
                 })
             }) : handler(false))
+        #else
+        hasCameraPermission() ? handler(true) : (needsToRequestCameraPermission() ?
+            AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { granted in
+                DispatchQueue.main.async(execute: { () -> Void in
+                    hasCameraPermission() ? handler(true) : handler(false)
+                })
+            }) : handler(false))
+        #endif
     }
     
     open var didCancel: (() -> Void)?

    
    open func setupDevices() {
        if #available(iOS 10.0, *) {
            self.captureDeviceFront = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)
            self.captureDeviceRear = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
        } else {
            let devices = AVCaptureDevice.devices(for: .video)
            
            for device in devices {
                if device.position == .back {

        }
        
        if #available(iOS 10.0, *) {
            if let photoCapture = self.captureOutput as? AVCapturePhotoOutput {
                #if swift(>=4.0)
                guard let connection = photoCapture.connection(with: .video) else { return }
                #else
                guard let connection = photoCapture.connection(withMediaType: AVMediaTypeVideo) else { return }
                #endif
                
                connection.videoOrientation = self.currentOrientation.toAVCaptureVideoOrientation()
                connection.videoScaleAndCropFactor = self.zoomScale
                
