我想知道是否有可能检测到用户是否正在从当前处于后台的应用程序调用.
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... ;-)
任何信息将不胜感激.
谢谢.
在CTCallCenter
中,有一个方法,callEventHandler
,你可以传递一个会被调用的block当呼叫事件发生时.在这个块中,您将被传递一个 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.
来自 文档:
如果您的应用程序在调用事件发生时处于活动状态,则系统会立即将该事件分派给您的处理程序.但是,调用事件也可能在您的应用程序暂停时发生.当它被挂起时,您的应用程序不会收到呼叫事件.当您的应用程序恢复活动状态时,它会为每个更改状态的调用接收一个调用事件 - 无论您的应用程序暂停时调用经历了多少状态更改.当您的应用程序返回活动状态时,发送到您的处理程序的单个调用事件描述了当时调用的状态.
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 中检测通话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!