Skip to content

Commit 0916e7e

Browse files
authored
Merge pull request #1 from fabioz23/master
fix for iOS >= 15.4 (cam preview not visible)
2 parents aa0f9dd + b1b9338 commit 0916e7e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/ios/QRScanner.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,18 @@ class QRScanner : CDVPlugin, AVCaptureMetadataOutputObjectsDelegate {
133133
if (captureSession?.isRunning != true){
134134
cameraView.backgroundColor = UIColor.clear
135135
self.webView!.superview!.insertSubview(cameraView, belowSubview: self.webView!)
136-
let availableVideoDevices = AVCaptureDevice.devices(for: AVMediaType.video)
137-
for device in availableVideoDevices {
138-
if device.position == AVCaptureDevice.Position.back {
139-
backCamera = device
136+
let session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
137+
let cameras = session.devices.compactMap { $0 }
138+
for camera in cameras {
139+
if camera.position == .front {
140+
self.frontCamera = camera
141+
140142
}
141-
else if device.position == AVCaptureDevice.Position.front {
142-
frontCamera = device
143+
if camera.position == .back {
144+
self.backCamera = camera
145+
try camera.lockForConfiguration()
146+
camera.focusMode = .continuousAutoFocus
147+
camera.unlockForConfiguration()
143148
}
144149
}
145150
// older iPods have no back camera
@@ -197,8 +202,9 @@ class QRScanner : CDVPlugin, AVCaptureMetadataOutputObjectsDelegate {
197202
}
198203

199204
@objc func makeOpaque(){
200-
self.webView?.isOpaque = false
201-
self.webView?.backgroundColor = UIColor.clear
205+
self.webView?.isOpaque = true
206+
self.webView?.backgroundColor = UIColor.white
207+
self.webView?.scrollView.backgroundColor = UIColor.white
202208
}
203209

204210
@objc func boolToNumberString(bool: Bool) -> String{
@@ -292,6 +298,7 @@ class QRScanner : CDVPlugin, AVCaptureMetadataOutputObjectsDelegate {
292298
@objc func show(_ command: CDVInvokedUrlCommand) {
293299
self.webView?.isOpaque = false
294300
self.webView?.backgroundColor = UIColor.clear
301+
self.webView?.scrollView.backgroundColor = UIColor.clear
295302
self.getStatus(command)
296303
}
297304

0 commit comments

Comments
 (0)