diff --git a/PayfritBeacon/Info.plist b/PayfritBeacon/Info.plist index 7ea74e1..43eff72 100644 --- a/PayfritBeacon/Info.plist +++ b/PayfritBeacon/Info.plist @@ -22,6 +22,8 @@ $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS + NSCameraUsageDescription + Payfrit Beacon needs camera access to scan QR codes on beacon labels for provisioning. NSBluetoothAlwaysUsageDescription Payfrit Beacon needs Bluetooth to detect and configure nearby beacons. NSBluetoothPeripheralUsageDescription diff --git a/PayfritBeacon/Views/QRScannerView.swift b/PayfritBeacon/Views/QRScannerView.swift index 4b9e830..d3a9d0f 100644 --- a/PayfritBeacon/Views/QRScannerView.swift +++ b/PayfritBeacon/Views/QRScannerView.swift @@ -241,17 +241,31 @@ final class CameraPreviewUIView: UIView { func setFlash(_ on: Bool) { guard let device = AVCaptureDevice.default(for: .video), device.hasTorch else { return } - try? device.lockForConfiguration() - device.torchMode = on ? .on : .off - device.unlockForConfiguration() + do { + try device.lockForConfiguration() + device.torchMode = on ? .on : .off + device.unlockForConfiguration() + } catch { + NSLog("[QRScanner] Failed to set torch: \(error.localizedDescription)") + } } private func setupCamera() { let session = AVCaptureSession() session.sessionPreset = .high - guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back), - let input = try? AVCaptureDeviceInput(device: device) else { return } + guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else { + NSLog("[QRScanner] ERROR: No back camera available") + return + } + + let input: AVCaptureDeviceInput + do { + input = try AVCaptureDeviceInput(device: device) + } catch { + NSLog("[QRScanner] ERROR: Failed to create camera input: \(error.localizedDescription)") + return + } if session.canAddInput(input) { session.addInput(input)