File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1201,20 +1201,30 @@ extension CameraViewController {
12011201 let audioDevice = AVCaptureDevice . default ( for: . audio)
12021202 let audioDeviceInput = try AVCaptureDeviceInput ( device: audioDevice!)
12031203
1204+ // Save torch mode before reconfiguring session (iOS resets torch on commitConfiguration)
1205+ let savedTorchMode = self . videoDeviceInput? . device. torchMode ?? . off
1206+
12041207 self . captureSession. beginConfiguration ( )
1205-
1208+
12061209 if self . captureSession. canAddInput ( audioDeviceInput) {
12071210 self . captureSession. addInput ( audioDeviceInput)
12081211 } else {
12091212 print ( " Could not add audio device input to the session " )
12101213 }
1211-
1214+
12121215 if self . captureSession. canAddOutput ( self . audioDataOutput) {
12131216 self . captureSession. addOutput ( self . audioDataOutput)
12141217 self . audioDataOutput. setSampleBufferDelegate ( self , queue: self . audioDataOutputQueue)
12151218 }
1216-
1219+
12171220 self . captureSession. commitConfiguration ( )
1221+
1222+ // Restore torch mode after session reconfiguration
1223+ if savedTorchMode != . off, let device = self . videoDeviceInput? . device, device. hasTorch {
1224+ try ? device. lockForConfiguration ( )
1225+ device. torchMode = savedTorchMode
1226+ device. unlockForConfiguration ( )
1227+ }
12181228
12191229 // Update audio connection
12201230 self . audioConnection = self . audioDataOutput. connection ( with: . audio)
You can’t perform that action at this time.
0 commit comments