Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we fire an event when ever there is Incoming and Outgoing call in iphone?

Can I fire an event when ever there is Incoming and Outgoing call ends on iphone? Axample of an event is calling a webservice .

like image 514
user601367 Avatar asked Jul 23 '11 05:07

user601367


2 Answers

Yes you can, but not necessarily immediately.

There is a framework, called the CoreTelephony framework, which has a CTCallCenter class. One of the properties on this class is the callEventHandler property. This is a block that gets fired when then state of a phone call changes. For example:

CTCallCenter *callCenter = ...; // get a CallCenter somehow; most likely as a global object or something similar?

[callCenter setCallEventHandler:^(CTCall *call) {
  if ([[call callState] isEqual:CTCallStateConnected]) {
    //this call has just connected
  } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
    //this call has just ended (dropped/hung up/etc)
  }
}];

That's really about all you can do with this. You don't get access to any phone numbers. The only other useful tidbit of information is an identifier property on CTCall so you uniquely identify a CTCall object.

CAUTION:

This event handler is not invoked unless your app is in the foreground! If you make and receive calls while the app is backgrounded, the event handler will not fire until your app becomes active again, at which point (according to the documentation linked to above) the event handler will get invoked once for each call that has changed state while the app was in the background.

like image 138
Dave DeLong Avatar answered Sep 21 '22 14:09

Dave DeLong


No but you do get callbacks into the app when those events happen.

    -(void)applicationWillResignActive:(UIApplication *)application{
        //our app is going to loose focus since thier is an incoming call
        [self pauseApp];
    }

    -(void)applicationDidBecomeActive:(UIApplication *)application{
            //the user declined the call and is returning to our app
            [self resumeApp];
    }
like image 38
Lee Armstrong Avatar answered Sep 22 '22 14:09

Lee Armstrong