IOS 5 - CTCallCenter not working for me

My phone: iOS 5.1.1 Jailbroken using Absynth2

What I'm trying to do: detect an incoming call or when a call is dialed ...

Ok, here is my code, which I placed inside AppDelegate under didEnterBackground , also tried in didResignActive - I have no errors, but I also do not get any results.

 callCenter = [[CTCallCenter alloc] init]; [callCenter setCallEventHandler:^(CTCall *call) { NSDictionary *dict = [NSDictionary dictionaryWithObject:call.callState forKey:@"callState"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"CTCallStateDidChange" object:nil userInfo:dict]; NSLog(@"state changed on call: %@", call); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callDial:) name:CTCallStateDialing object:nil]; 

any help is appreciated. thanks!

+2
source share
2 answers

The problem is that iOS does not seem to send notifications to UIApplications in the background. From an iOS document for CTCallCenter :

If your application is active when a call event occurs, the system sends an event to your handler immediately. However, call events may also take place while your application is paused. While it is paused, your application does not accept call events.

Since you hacked jailbroken, why not make your launcher daemon “app”? Then it can work all the time as a service. If you do this, then the following code should receive your notifications (I tested this on jailbroken iOS 5.0.1 iPhone 4):

 @property (nonatomic, strong) CTCallCenter* callCenter; 

and register for notifications using:

 - (void) registerForCalls { self.callCenter = [[CTCallCenter alloc] init]; NSLog(@"registering for call center events"); [callCenter setCallEventHandler: ^(CTCall* call) { if ([call.callState isEqualToString: CTCallStateConnected]) { } else if ([call.callState isEqualToString: CTCallStateDialing]) { } else if ([call.callState isEqualToString: CTCallStateDisconnected]) { } else if ([call.callState isEqualToString: CTCallStateIncoming]) { } NSLog(@"\n\n callEventHandler: %@ \n\n", call.callState); }]; } 

Here's a good tutorial on how to create Launch Daemons , if you haven't already.

If you also have a graphical component for your application, you can create two parts: a launch daemon to run all the time and a user interface application that starts when the user starts. They can communicate with each other with notifications if necessary.

+5
source

If you want your application to always run in the background, you need to make a Voip application application. You can also do a little trick that makes your app play endless silent music when it goes in the background.

0
source

All Articles