简体   繁体   中英

How to detect other VOIP call (iOS)?

I am working on an app that allows video calls using an SDK that utilises webRTC on iOS.

Intended functionality is that if another call is instantiated after my app has instantiated a call, I want my app to mute audio in both directions in my call until that call has ended, in which case audio is restored.

I have encountered a problem where I want to detect other calls that make VOIP calls (for example WeChat and Facebook Messenger).

In the case of WeChat I have solved this exploiting that it interrupts the shared audio session (of AVAudioSession). The code that handles this is as follows:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector
     (audioSessionInterrupted:)
... 

name:AVAudioSessionInterruptionNotification object:nil];
- (void) audioSessionInterrupted:(NSNotification*)notification
{
    if(notification.name == AVAudioSessionInterruptionNotification)
    {
        NSDictionary* userInfo = notification.userInfo;
        int result = userInfo[AVAudioSessionInterruptionTypeKey];
        if(result == AVAudioSessionInterruptionTypeBegan)
        {
            [[AVAudioSession sharedInstance] setActive:NO error:nil];
            [self setAudioEnabled:NO];
        }
        else if (result == AVAudioSessionInterruptionTypeEnded)
        {
            [[AVAudioSession sharedInstance] setActive:YES error:nil];
            [self setAudioEnabled:YES];

        }
    }
}

However, for Facebook Messenger, this method is never called. I speculate from this that WeChat may be demanding exclusive access to the shared audio session (and thus causing an interruption of the audio session with my app) whereas Facebook Messenger chooses to mix its audio, or uses a separate audio session when a call is instantiated.

My question is does there exist another way of detecting other VOIP calls, possibly using the CallKit framework? My app uses CallKit to prompt user for incoming calls, and records ingoing/outgoing calls in the iOS phone log.

I would recommend checking all current native calls. All calls that are registered through CallKit are also considered native calls and trigger a call on this object, from CoreTelephony:

CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler = ^(CTCall* call) {
    //Native call changes are triggered here
};

For detecting VOIP calls from applications that do not support CallKit, this is harder. A possibility is listening to changes to the AVAudioUnit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM