Closed vishalkalola1 closed 5 years ago
Hello, Vishal
Please add this line for swift 4.2 in your projects.
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.duckOthers, .defaultToSpeaker])
} else {
try AVAudioSessionPatch.setSession(AVAudioSession.sharedInstance(), category: .playAndRecord, with: [.defaultToSpeaker, .duckOthers])
}
Make AVAudioSessionPatch objective-c file.
Add this code the in AVAudioSessionPatch.h
+ (BOOL)setSession:(AVAudioSession *)session category:(AVAudioSessionCategory)category withOptions:(AVAudioSessionCategoryOptions)options error:(__autoreleasing NSError **)outError;
And in AVAudioSessionPatch.m
+ (BOOL)setSession:(AVAudioSession *)session category:(AVAudioSessionCategory)category withOptions:(AVAudioSessionCategoryOptions)options error:(__autoreleasing NSError **)outError {
return [session setCategory:category withOptions:options error:outError];
}
import the #import "AVAudioSessionPatch.h"
in your project Bridging-Header files.
Thanks
//try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, with: [.duckOthers, .defaultToSpeaker])
without this method audio not record.