在iOS4中检测呼叫状态 [英] Detecting call state in iOS4

查看:113
本文介绍了在iOS4中检测呼叫状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢。

推荐答案

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

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.

例如:

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

编辑:重新阅读你的问题,你想要暂停这些事件,对吗?我不认为这是可能的。

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

来自 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.

这篇关于在iOS4中检测呼叫状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆