5

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

tshepang
  • 12,111
  • 21
  • 91
  • 136
user601367
  • 2,308
  • 12
  • 34
  • 44

3 Answers3

4

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.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
  • If my app originates an outgoing call and subscribes to the disconnect event, in my event handler can I send a local message that will prompt the user to return to my app? Or do you know of a less cumbersome way to return focus to an app after an outgoing call ends? – JeremyWeir Aug 20 '11 at 00:27
1

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];
    }
Lee Armstrong
  • 11,420
  • 15
  • 74
  • 122
  • 2
    This doesn't necessarily means that there is an incoming call. Other app, notification or the home button will fire it. – Erre Efe Jul 23 '11 at 05:42
0

No. As of the current SDK, this is not possible. Apple does not allow apps to have such hooks.

Benjamin Mayo
  • 6,649
  • 2
  • 26
  • 25
  • Hmm. Didn't know about this. I am correct in thinking you cannot have your app "wake up" in response to a call, though? You have to wait until it enters the foreground (by user input) again? – Benjamin Mayo Jul 23 '11 at 19:28
  • that's correct. It's simply a way to know that stuff happened and react to it, but only when your app is active. – Dave DeLong Jul 23 '11 at 20:02