Search code examples
iosinterrupt-handlingphone-call

iOS monitoring call state in background state


My app is recording all the time and it should play sound and stop recording when phone call detected. After the phone call, recording should goes on.

I've had these task done with CTCallCenter in foreground.

However, CTCallCenter doesn't work properly while my app is in background. Even if add background flag "VoIp" to my app, CTCallCenter would miss CallDisconnected. Is this a bug of iOS?

So I tried "AVAudioSessionInterruptionNotification". It seemed that it never miss a single InterruptionBegin and InterruptionEnd. But It doesn't work as I need to play sound after InterruptionBegin detected. Apparently, InterruptionBegin means my audio session is inactive and no sound could be made.

Is there any way to make CTCallCenter workable in my case?


Solution

  • The only way I have found to check whether there is a GSM call in the background is by checking the availability of the Audio Unit, which is used by the GSM call.

    So

    BOOL isOtherAudioPlaying=[[AVAudioSession sharedInstance] isOtherAudioPlaying];
    

    Will tell you whether you have an active GSM call. I'm not so sure if it has side effects with other apps that are using the audio unit. I have tried it with Camera and Voice Memos and they seem that they are paused and as a consequence it doesn't influence your app.