mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Merge pull request #127 from risingsunomi/Swift4
Fix for switching camera from front to back and back to front
This commit is contained in:
commit
85d713d643
1 changed files with 93 additions and 78 deletions
|
|
@ -885,7 +885,26 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
/// Get Devices
|
/// Get Devices
|
||||||
|
|
||||||
fileprivate class func deviceWithMediaType(_ mediaType: String, preferringPosition position: AVCaptureDevice.Position) -> AVCaptureDevice? {
|
fileprivate class func deviceWithMediaType(_ mediaType: String, preferringPosition position: AVCaptureDevice.Position) -> AVCaptureDevice? {
|
||||||
return AVCaptureDevice.devices(for: AVMediaType(rawValue: mediaType)).first
|
if #available(iOS 10.0, *) {
|
||||||
|
let avDevice = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType(rawValue: mediaType), position: position)
|
||||||
|
return avDevice
|
||||||
|
} else {
|
||||||
|
// Fallback on earlier versions
|
||||||
|
let avDevice = AVCaptureDevice.devices(for: AVMediaType(rawValue: mediaType))
|
||||||
|
var avDeviceNum = 0
|
||||||
|
for device in avDevice {
|
||||||
|
print("deviceWithMediaType Position: \(device.position.rawValue)")
|
||||||
|
if device.position == position {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
avDeviceNum += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return avDevice[avDeviceNum]
|
||||||
|
}
|
||||||
|
|
||||||
|
//return AVCaptureDevice.devices(for: AVMediaType(rawValue: mediaType), position: position).first
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable or disable flash for photo
|
/// Enable or disable flash for photo
|
||||||
|
|
@ -1217,7 +1236,3 @@ extension SwiftyCamViewController : UIGestureRecognizerDelegate {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue