开发者

Detecting call state in 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 en开发者_如何学JAVAded 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜