0

I need to write a background application in iOS which listens to incoming phone calls on the iPhone.

Is it possible? Can anyone suggest some good pointers ?

Thankyou

revolutionary
  • 3,314
  • 4
  • 36
  • 53

2 Answers2

6

This would be very much against Apple's privacy policy and there's no chance an app like this would be approved.

There are call recording apps that sneak around this restriction, though, but they use third party services and no actual built-in iPhone API's.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
4

You can do it in applicationWillEnterForeground using CTCallCenter's CTCallState properties. Don't forget to import the CoreTelephony framework. Here's an example:

#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [callCenter setCallEventHandler:^(CTCall *call) {
        if ([[call callState] isEqual:CTCallStateIncoming] || [[call callState] isEqual:CTCallStateDialing]) {

            if ([viewController isPlaying])
            {
                NSLog(@"Call was started.");
            }
        } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
            if (callWasStarted)
            {
               NSLog(@"Call was ended.");
            }
        }
    }];
}