I can't detect end of call (state CallStateDisconnected), if I make call from my app. But if I receive call when my app is active, I can detect that state. I also receive state CTCallStateDialing twice or 3 times when call starts from my app. It used to be working under iOS5, this problems occured with iOS6.
My app del code;
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler = ^(CTCall* call) {
// anounce that we've had a state change in our call center
NSDictionary *dict = [NSDictionary dictionaryWithObject:call.callState forKey:@"callState"]; //BREAKPOINT HERE
[[NSNotificationCenter defaultCenter] postNotificationName:@"CTCallStateDidChange" object:self userInfo:dict];
};
Strange thing is that it all works, if I put breakpoint in callEventHandler block and resume execution after call finishes, then I get CallStateDisconnected correctly.
Then I subscribe to notifications in my view controller and execute this code when I receive them:
- (void)ctCallStateDidChange1:(NSNotification *)notification
{
NSString *call = [[notification userInfo] objectForKey:@"callState"];
if ([call isEqualToString:CTCallStateDisconnected])
{
NSLog(@"Call has been disconnected");
}
else if([call isEqualToString:CTCallStateDialing])
{
NSLog(@"Call start");
}
else if ([call isEqualToString:CTCallStateConnected])
{
NSLog(@"Call has just been connected");
}
else if([call isEqualToString:CTCallStateIncoming])
{
NSLog(@"Call is incoming");
}
else
{
NSLog(@"None");
}
}
I make call from my app like this:
UIWebView *callWebview = [[UIWebView alloc] init];
[self.view addSubview:callWebview];
NSURL *telURL = [NSURL URLWithString:number];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
I also logged app state and I get - (void)applicationDidBecomeActive:(UIApplication *)application
after I start call, then I go to - (void)applicationDidEnterBackground:(UIApplication *)application
and after call is finished back to - (void)applicationDidBecomeActive:(UIApplication *)application.
Is that strange, that DidBecomeActive
is called after call is made and before going to background?
Here's the log from an iOS 5 phone:
and here's the log from an iOS 6 phone:
The "disconnected" message has just disappeared. (This isn't an answer, it's an observation.)
Here's the code I used. I I created a single-view application in xcode with a single button in the xib, and this is the whole of my UIViewController: