iOS4中检测通话状态

发布于 2024-09-11 03:31:56 字数 177 浏览 3 评论 0原文

我想知道是否有可能检测用户是否正在从当前处于后台的应用程序进行通话。

或者,如果通话是从我的应用程序发起的,则在通话结束时收到通知。

或者,更重要的是 - 是否有可能检测哪个应用程序位于前台?
我不相信这是可能的,但我必须尝试...;-)

任何信息将不胜感激。

谢谢。

I would like to know if there is a possibility to detect if the user is in call from an application that is currently in background.

Or, receive a notification when the call is ended if the call was initiated from my app.

Or, even more than that - is there a possibility to detect which app is in foreground?
I don't believe that this is possible but I had to try... ;-)

Any info will be appreciated.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2024-09-18 03:31:56

CTCallCenter 中,有一个 callEventHandler 方法,您可以传递一个在呼叫事件发生时将被调用的块。在此块中,您将传递一个 CTCall 对象,并可以获得 callState。因此,您可以在呼叫发起或结束时收到通知,并进行适当的处​​理。您无法得知哪个应用程序发起了调用,但如果您在调用时设置了 ivar,则可以知道是您的应用程序发出了调用。

例如:

CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call){
    if (call.callState == CTCallStateDisconnected)
    { 
        //handle disconnect
    }
};

编辑:重新阅读您的问题,您希望在暂停时发生这些事件,对吗?我认为这是不可能的。

来自 文档

如果您的应用程序在调用事件发生时处于活动状态,系统会立即将该事件分派给您的处理程序。但是,呼叫事件也可能在应用程序暂停时发生。当它被挂起时,您的应用程序不会接收呼叫事件。当您的应用程序恢复活动状态时,它会收到每个更改状态的调用的单个调用事件,无论应用程序挂起时该调用经历了多少次状态更改。当您的应用程序返回到活动状态时,发送到您的处理程序的单个调用事件描述了当时的调用状态。

In CTCallCenter, there is a method, callEventHandler that you can pass a block that will get called when call events happen. In this block, you'll be passed a CTCall object, and can get the callState. So, you can get a notification when a call is initiated or ended, and handle it appropriately. You can't get which application initiated the call, but if you set an ivar when you make the call, you can tell that it's your application that made the call.

For example:

CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call){
    if (call.callState == CTCallStateDisconnected)
    { 
        //handle disconnect
    }
};

EDIT: Re-reading your question, you want these events while you are suspended, correct? I don't think that's possible.

From the docs:

If your application is active when a call event takes place, the system dispatches the event to your handler immediately. However, call events can also take place while your application is suspended. While it is suspended, your application does not receive call events. When your application resumes the active state, it receives a single call event for each call that changed state—no matter how many state changes the call experienced while your application was suspended. The single call event sent to your handler, upon your application returning to the active state, describes the call’s state at that time.

蓝戈者 2024-09-18 03:31:56

如果您的应用程序在后台运行并且有 AVAudioSession 正在进行,您将在 AVAudioSessionDelegate 告诉您接到电话时您的 AVAudioSession 已被中断。 AFAIK 这就是您获得的所有信息。

If you're app is running in the background and has an AVAudioSession going, you will receive callbacks on the AVAudioSessionDelegate telling you that your AVAudioSession has been interrupted when a phone call is received. AFAIK that's all the info you get.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文