Haptic feedback not playing nice with AVFoundation? (UIImpactFeedbackGenerator, etc)

 ̄綄美尐妖づ 提交于 2019-12-08 01:42:05

问题


I'm trying to have a video / camera view in the background while I also allow for haptic feedback in my app for various actions, but it seems that AVFoundation is not playing nice with any of the calls I am making that involve the haptic calls:

     if #available(iOS 10.0, *) {

        let generator = UIImpactFeedbackGenerator(style: .light)
            generator.prepare()
            generator.impactOccurred()
// More:

      let feedbackGenerator  = UISelectionFeedbackGenerator()
                feedbackGenerator.selectionChanged()

}

Haptic feedback works great and as expected as long as the AVFoundation stuff is commented out. Any ideas?

Using:

    captureSession = AVCaptureSession()

AND:

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)

Thanks


回答1:


I assume that if you are using AVCaptureSession then you probably have code like this:

do {
    let audioDevice = AVCaptureDevice.default(for: .audio)
    let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice!)

    if captureSession.canAddInput(audioDeviceInput) {
        captureSession.addInput(audioDeviceInput)
    } else {
        print("Could not add audio device input to the session")
    }
} catch {
    print("Could not create audio device input: \(error)")
}

So audio input is not playing well with haptic engine. You have to remove audio input from capture session before you are playing haptic and then add it back.



来源:https://stackoverflow.com/questions/44212923/haptic-feedback-not-playing-nice-with-avfoundation-uiimpactfeedbackgenerator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!