Using AVAudioSession AVAudioSessionCategoryPlayAndRecord disables all push notifications sounds and vibrations. Even with the app in the background

I am developing an application that takes some notes when the application is in the foreground and in the background. What works. However, I noticed that the β€œsystem” sounds like alarm sounds and the vibrations are muted whenever my audio session is active (see below). This is true even if the application is in the background.

As a result, I stop receiving / vibe notification sounds for standard things like text messages while my application is in the background and recording is on.

The audio session is set as follows:

AVAudioSession* session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error]; 

Obviously these sounds / vibrations do not mix, so I think they are muffled.

Is there any way around this (while keeping an active record)? . How can I record and allow the user to receive sound notifications and vibrations?

+6
source share
1 answer

You can try the following:

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:(AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionDuckOthers) error:nil]; 

Alternatively, you can experiment with deactivating the audio session using this:

 [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; 

And then reactivate it:

 [[AVAudioSession sharedInstance] setActive:YES error:nil]; 
+1
source

Source: https://habr.com/ru/post/987820/


All Articles