The application is recording audio and should stop recording audio when there is an interruption, such as a phone call, and then resume recording audio when the telephone call ends.
The application is currently logged when there is a phone call, but when I hung up, the application did not register that the interrupt was over. (I do not have other applications open).
With function delegates
See the code below in my ViewController.
func audioRecorderBeginInterruption(recorder: AVAudioRecorder){
print("* * * * * * * inside begin interruption")}
func audioRecorderEndInterruption(recorder: AVAudioRecorder, withFlags flags: Int) {
print("* * * * * * * inside end interruption")
}
With notifications
I also tried to handle interruptions with notifications, but .Ended is still not processed if I do not receive a phone call and I reject the call. View Code in AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let center = NSNotificationCenter.defaultCenter()
center.addObserver(self,
selector:"sessionInterrupted:",
name:AVAudioSessionInterruptionNotification,
object:AVAudioSession.sharedInstance())
return true
}
func sessionInterrupted(notification: NSNotification){
if let typeValue = notification.userInfo?[AVAudioSessionInterruptionTypeKey] as? NSNumber{
if let type = AVAudioSessionInterruptionType(rawValue: typeValue.unsignedLongValue){
if type == .Began{
print("interruption: began")
} else{
print("interruption: ended")
}
}
Related solutions that didn't work for me
- :
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];, - .
MixWithOthers, ,
, "Ended" , , , , , , , . , , .
: IOS AVAudioSession
, , DropVox:
. DropVox , "". , DropVox 7, " ".
, , , . , , , .
?