UIImpactFeedbackGenerator Not Working When Audio Device Added to AVCaptureSession

后端 未结 2 2023
时光取名叫无心
时光取名叫无心 2021-02-07 10:58

Adding microphone audio input to AVCaptureSession seems to disable UIImpactFeedbackGenerator.

let audioDevice = AVCaptureDevice.defaultD         


        
2条回答
  •  眼角桃花
    2021-02-07 11:26

    This seems to be an intentional behavior.

    You can stop the capture session, play the haptic, then resume the capture session, which appears to be what the camera app is doing, as when you peek the camera feed goes to a blurred static image of the last frame captured. For example:

    self.session.stopRunning()
    // Play haptic
    UINotificationFeedbackGenerator().notificationOccurred(.warning)
    // Not completely sure if this delay is needed but you might need to wait until the run loop after the haptic plays to resume capture session
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
    {
    
        self.session.startRunning()
    }
    

提交回复
热议问题