简体   繁体   English

如何检测其他VOIP呼叫(iOS)?

[英]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. 我正在开发一个应用程序,允许使用在iOS上使用webRTC的SDK进行视频通话。

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). 我遇到了一个问题,我想检测其他拨打VOIP电话的电话(例如WeChat和Facebook Messenger)。

In the case of WeChat I have solved this exploiting that it interrupts the shared audio session (of AVAudioSession). 在WeChat的情况下,我已经解决了这个问题,它中断了共享音频会话(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. 但是,对于Facebook Messenger,从不调用此方法。 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. 我从中推测微信可能要求独占访问共享音频会话(从而导致我的应用程序中断音频会话)而Facebook Messenger选择混合其音频,或者在实例化呼叫时使用单独的音频会话。

My question is does there exist another way of detecting other VOIP calls, possibly using the CallKit framework? 我的问题是,是否存在另一种检测其他VOIP调用的方法,可能使用CallKit框架? My app uses CallKit to prompt user for incoming calls, and records ingoing/outgoing calls in the iOS phone log. 我的应用程序使用CallKit提示用户接听来电,并在iOS手机日志中记录进出呼叫。

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: 通过CallKit注册的所有调用也被视为本机调用,并从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. 为了检测来自不支持CallKit的应用程序的VOIP调用,这更难。 A possibility is listening to changes to the AVAudioUnit. 有可能是听AVAudioUnit的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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