I make call from my app with this code (i use webview because after the call finishes, i dont want to show dialer app ):
UIWebView *callWebview = [[UIWebView alloc] init];
[self.view addSubview:callWebview];
NSURL *telURL = [NSURL URLWithString:tel];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
I detect end of call with subscribing to notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ctCallStateDidChange1:) name:@"CTCallStateDidChange" object:nil];
- (void)ctCallStateDidChange1:(NSNotification *)notification
{
NSString *call = [[notification userInfo] objectForKey:@"callState"];
if ([call isEqualToString:CTCallStateDisconnected])
{
NSLog(@"Call has been disconnected");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Obvestilo" message:@"Some text?"
delegate:self cancelButtonTitle:@"Yes" otherButtonTitles: @"No", nil];
[alert show];
}
}
}
I need to show alertview after the call finishes and control is returend to my app, but sometimes it takes some time when the end of call is detected with notification and my app stays nonresponsive during this period.
Do you have any ideas what to do?
The detection of end of call with notifications is correct. What i had to do is to add this line after the call was finished (so the command executed on main thread):
dispatch_async(dispatch_get_main_queue(), ^{
[self showAlert];
});