Delegate to know when phone call ends which was initiated by app

无人久伴 提交于 2019-12-04 15:07:59
Sahana Kini

CoreTelephony framework has a CTCallCenter Class with callEventHandler property.

@property (nonatomic, copy) void (^callEventHandler)(CTCall*);

You will have to define a handler block in your application and assign it to this property. If your application is active when a call event takes place, the system dispatches the event to your handler immediately when call state changes. Refer apple documents found here.

I used below code to get notified of call events.

// Create CTCallCenter object
callCenter = [[CTCallCenter alloc] init];
// Assign event handler. This will be called on each call event
self.callCenter.callEventHandler = ^(CTCall* call) {

    // If call ended
    if (call.callState == CTCallStateDisconnected)
    {
        NSLog(@"Call ended.");
    }
};

For other call states check out Call States. For more info on CTCallCenter look at Apple doc for CTCallCenter.

You should be implementing this delegate method of UIWebView

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

on end call operation your webview will notify this delegate method about your action perform and you can handle it in there for example

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked )
    {
        NSURL *url = [request URL];
        NSLog(@"URL ===== %@",url);
        // you can check your end call operation URL and handle it accordingly
        if ([[url absoluteString] rangeOfString:@"#"].location == NSNotFound)
        {
            [[UIApplication sharedApplication] openURL:[request URL]];
            return NO;
        }
        //return NO;

    }
    return YES;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!