diff --git a/ios/CameraView.swift b/ios/CameraView.swift index 2bc3bb9..597cbf6 100644 --- a/ios/CameraView.swift +++ b/ios/CameraView.swift @@ -293,6 +293,7 @@ final class CameraView: UIView { // allow background music playback try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: [.mixWithOthers, .allowBluetoothA2DP, .defaultToSpeaker]) } + audioSession.trySetAllowHaptics(true) // activate current audio session because camera is active try audioSession.setActive(true) } catch let error as NSError { diff --git a/ios/Extensions/AVAudioSession+trySetAllowHaptics.swift b/ios/Extensions/AVAudioSession+trySetAllowHaptics.swift new file mode 100644 index 0000000..cd6a38f --- /dev/null +++ b/ios/Extensions/AVAudioSession+trySetAllowHaptics.swift @@ -0,0 +1,23 @@ +// +// AVAudioSession+trySetAllowHaptics.swift +// VisionCamera +// +// Created by Marc Rousavy on 26.03.21. +// Copyright © 2021 Facebook. All rights reserved. +// + +import Foundation +import AVFoundation + +extension AVAudioSession { + /** + Tries to set allowHapticsAndSystemSoundsDuringRecording and ignore errors. + */ + func trySetAllowHaptics(_ allowHaptics: Bool) { + if #available(iOS 13.0, *) { + if !audioSession.allowHapticsAndSystemSoundsDuringRecording { + try? audioSession.setAllowHapticsAndSystemSoundsDuringRecording(true) + } + } + } +} diff --git a/ios/VisionCamera.xcodeproj/project.pbxproj b/ios/VisionCamera.xcodeproj/project.pbxproj index ba7c230..261ceb6 100644 --- a/ios/VisionCamera.xcodeproj/project.pbxproj +++ b/ios/VisionCamera.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + B86DC971260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86DC970260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift */; }; B887518525E0102000DB86D6 /* PhotoCaptureDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B887515C25E0102000DB86D6 /* PhotoCaptureDelegate.swift */; }; B887518625E0102000DB86D6 /* CameraView+RecordVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B887515D25E0102000DB86D6 /* CameraView+RecordVideo.swift */; }; B887518725E0102000DB86D6 /* CameraViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B887515F25E0102000DB86D6 /* CameraViewManager.m */; }; @@ -60,6 +61,7 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libVisionCamera.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libVisionCamera.a; sourceTree = BUILT_PRODUCTS_DIR; }; + B86DC970260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVAudioSession+trySetAllowHaptics.swift"; sourceTree = ""; }; B887515C25E0102000DB86D6 /* PhotoCaptureDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureDelegate.swift; sourceTree = ""; }; B887515D25E0102000DB86D6 /* CameraView+RecordVideo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CameraView+RecordVideo.swift"; sourceTree = ""; }; B887515E25E0102000DB86D6 /* CameraBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CameraBridge.h; sourceTree = ""; }; @@ -144,7 +146,7 @@ B887516125E0102000DB86D6 /* Extensions */ = { isa = PBXGroup; children = ( - B887516225E0102000DB86D6 /* Collection+safe.swift */, + B86DC970260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift */, B887516325E0102000DB86D6 /* AVCaptureDevice+neutralZoom.swift */, B887516425E0102000DB86D6 /* AVCaptureDevice.Format+isBetterThan.swift */, B887516525E0102000DB86D6 /* AVCaptureDevice+isMultiCam.swift */, @@ -154,6 +156,7 @@ B887516925E0102000DB86D6 /* AVCaptureDevice.Format+matchesFilter.swift */, B887516A25E0102000DB86D6 /* AVCaptureDevice.Format+toDictionary.swift */, B887516B25E0102000DB86D6 /* AVCaptureMovieFileOutput+mirror.swift */, + B887516225E0102000DB86D6 /* Collection+safe.swift */, ); path = Extensions; sourceTree = ""; @@ -320,6 +323,7 @@ B88751A025E0102000DB86D6 /* AVAuthorizationStatus+descriptor.swift in Sources */, B887519C25E0102000DB86D6 /* AVCaptureDevice.TorchMode+descriptor.swift in Sources */, B88751A525E0102000DB86D6 /* CameraView+Focus.swift in Sources */, + B86DC971260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift in Sources */, B887519325E0102000DB86D6 /* CameraView+CodeScanning.swift in Sources */, B887519E25E0102000DB86D6 /* AVCapturePhotoOutput.QualityPrioritization+descriptor.swift in Sources */, B887518825E0102000DB86D6 /* VideoCaptureDelegate.swift in Sources */,