iOS - 通话何时发出通知?

时间:2011-09-23 14:52:01

标签: objective-c ios notifications

在iOS手机上进行GSM / CDMA通话时是否可以通知或检测到?

我有一个在后台使用音频的应用程序,我希望能够检测到何时正在进行通话,以便我的应用程序可以做出相应的反应,以便无论如何都不会干扰移动电话。

基本上我希望能够检测到正在进行呼叫的时间,这样如果用户在通话时输入我的应用程序,我可以禁用某些功能。

所以我想知道如何检测到设备上正在进行蜂窝呼叫?

4 个答案:

答案 0 :(得分:9)

从iOS 4开始,您可以使用Core Telephony框架中的CTCallCenter类来注册事件处理程序,以便在呼叫开始或结束时通知您的应用。它为您提供的CTCall具有callState属性,可以是CTCallStateDialingCTCallStateIncomingCTCallStateConnected,或者 - 当它结束时 - CTCallStateDisconnected

答案 1 :(得分:2)

从iOS 6开始,你应该:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAudioInterruption:) name:AVAudioSessionInterruptionNotification object:session

然后:

- (void)onAudioInterruption:(NSNotification*)notification
{
    NSDictionary *info = notification.userInfo;
    NSUInteger type = [[info valueForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];

    if (type == AVAudioSessionInterruptionTypeBegan) {
        // stop audio (or whatever)
    } else if (type == AVAudioSessionInterruptionTypeEnded) {
        // restart audio (or whatever)
    }
}

答案 2 :(得分:1)

答案 3 :(得分:0)

你可以使用CoreTelephony framework.But你必须使用一些私人api.And我有一些演示代码。 https://github.com/edison0951/AppNotifyBySMSDemo。最后的解决方案是MAP。这与SMS notifications in iOS6

相同