iOS – 通知何时发生?

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

我有一个应用程序,在后台使用audio,我希望能够检测到一个电话正在发生,以便我的应用程序可以作出相应的反应,以便不打扰蜂窝电话。

基本上,我希望能够检测何时发生呼叫,以便如果用户在通话中input我的应用程序,我可以禁用某些function。

所以我想知道如何检测到设备上正在发生蜂窝通话?

从iOS 4开始,可以使用Core Telephony框架中的CTCallCenter类来注册事件处理程序,以便在通话开始或结束时通知您的应用程序。 它给你的callState有一个callState属性,它可以是CTCallStateDialingCTCallStateIncomingCTCallStateConnected ,或者当它结束时, CTCallStateDisconnected

看看AVAudioSessionDelegate协议 。

你可以使用CoreTelephony框架。但是你必须使用一些私人API。我有一些演示代码。 https://github.com/edison0951/AppNotifyBySMSDemo 。 最后的解决scheme是MAP.This与iOS6中的短信通知相同

从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) } }