How to Get a Call Event Using Ctcallcenter:Setcalleventhandler: That Occurred While the App Was Suspended

How to get a call event using CTCallCenter:setCallEventHandler: that occurred while the app was suspended?

I've found a solution but I have no idea why it's working. Only thing I can think of is a bug in GCD and/or CoreTelephony.

Basically, I allocate two instances of CTCallCenter like this

void (^block)(CTCall*) = ^(CTCall* call) { NSLog(@"%@", call.callState); };

-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
callCenter1 = [[CTCallCenter alloc] init];
callCenter1.callEventHandler = block;

callCenter2 = [[CTCallCenter alloc] init];
callCenter2.callEventHandler = block;

return YES;
}

Similar Code in Swift:

func block (call:CTCall!) {
println(call.callState)
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//Declare callcenter in the class like 'var callcenter = CTCallCenter()'
callcenter.callEventHandler = block

return true
}

To test this I made a call, answered it and then hanged up it while app was in background. When I launched it I received 3 call events: incoming, connected, disconnected.

CTCallCenter - Call Event Handler - in background state

All tests that I've done I can't receive any using callEventHandler when the application is in background. But, when the application is in foreground, all nicely work.

The socket works, because iOS handles it for you app and deliver the packtes accordingly. But for that, you need to create a voip socket and add voip to UIBackgroundModes to your App-Info.plist.

How does the Navita TEM app get call log information?

Here is what I've found from Navita TEM disassembly and it's resources.

Application uses two background modes - location and audio. You can see it in the Info.plist file. When you enable phone calls logging application will also enable "alerts" and "Real-time" switches. When "alerts" enabled application infinitely loops in background "bg-sound.mp3" file which has no sound, it's just silence. Because of that it doesn't use hacks like this one How to get a call event using CTCallCenter:setCallEventHandler: that occurred while the app was suspended? . It's similar trick to location used in order to keep the app running in background and receive phone call events. Somehow this was not rejected from the AppStore.



Related Topics



Leave a reply



Submit