Vibrate iPhone while Recording
audio, cocoa-touch, iphone, objective-c
Solution
AT LAST! As of iOS 13, there is a new property on AVAudioSession
let _ = try? AVAudioSession.sharedInstance().setCategory(.playAndRecord)
if #available(iOS 13.0, *) {
let _ = try? AVAudioSession.sharedInstance().setAllowHapticsAndSystemSoundsDuringRecording(true)
}
Problem
I'm trying to get my iPhone to vibrate while I'm recording. I've tried this: ``` UInt32 category = kAudioSessionCategory_PlayAndRecord; status |= AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); UInt32 allowMixing = true; status |= AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers, // 1 sizeof (allowMixing), // 2 &allowMixing // 3 ); status |= AudioSessionSetProperty( kAudioSessionProperty_OtherMixableAudioShouldDuck, // 1 sizeof (allowMixing), // 2 &allowMixing // 3 ); ``` As suggested here. Then vibrate the device later on by calling ``` AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); ``` But it does not work. But it does not vibrate. It records fine, and if I call a vibrate moments before I stop recording it vibrates after stop it. Apparently it's a bug, does anyone know of a work around?