问题描述
我有一个代码,使用以下代码拨打电话:
c code code code code code codeCall c $ c> property。@property(nonatomic,copy)void(^ callEventHandler)(CTCall *);
您将必须在应用程序中定义一个处理程序块并将其分配给此属性。
如果您的应用程序在发生呼叫事件时处于活动状态,则当呼叫状态更改时,系统会立即将事件发送到您的处理程序。请参阅找到的Apple文档I have a code which places a phone call using below code :
// Make a call to given phone number - (void)callPhoneNumber:(NSString *)phoneNumber { if (!self.webview) self.webview = [[UIWebView alloc] init]; self.webview.delegate = self; // Remove non-digits from phone number phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""]; // Make a call NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumber]]; [self.webview loadRequest:[NSURLRequest requestWithURL:url]]; [self.view addSubview:self.webview]; }This makes a call. What I want is, I want to know when user ends a call. I have to perform an operation when user ends a call. Is there any way for it?
What I tried is, I set delegate of webview to current controller. But none of the delegate methods is called.
- (void)webViewDidStartLoad:(UIWebView *)webView { DLog(@"Start Loading"); } - (void)webViewDidFinishLoad:(UIWebView *)webView { DLog(@"Finish Loading"); } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { DLog(@"Did fail with error : %@", error); }I don't know if you need this info but I use webview so that when phone call is made, flow remains within the app and on call end, app screen is displayed rather than user manually coming to app from native contact app.
解决方案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.
这篇关于代表由应用程序发起的电话结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!