yeahdongcn / RSBarcodes_Swift

1D and 2D barcodes reader and generators for iOS 8 with delightful controls. Now Swift.
MIT License
707 stars 185 forks source link

devices(withMediaType:) is deprecated in IOS 10 #72

Closed aleene closed 7 years ago

aleene commented 7 years ago

We are supposed to use AVCaptureDeviceDiscoverySession.

not sure how I should change this.

yeahdongcn commented 7 years ago

Currently I'm using

AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
aleene commented 7 years ago

I changed captureDevice() to this, in order to remove the compiler warning:

` func captureDevice() -> AVCaptureDevice? { let allTypes = [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInWideAngleCamera, AVCaptureDeviceType.builtInTelephotoCamera ]

    if let currentSession = AVCaptureDeviceDiscoverySession.init(deviceTypes: allTypes, mediaType: AVMediaTypeVideo, position: (self.device?.position)!) {
        if let validDevices = currentSession.devices {
            for device in validDevices {

                if self.device?.position == AVCaptureDevicePosition.back {
                    if device.position == AVCaptureDevicePosition.front {
                        return device
                    }
                } else if self.device?.position == AVCaptureDevicePosition.front {
                    if device.position == AVCaptureDevicePosition.back {
                        return device
                    }
                }
            }
        }
    }
    return nil
}

`