Detecting call state in iOS4

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.

Leave a Comment