代表由应用程序发起的电话结束 [英] Delegate to know when phone call ends which was initiated by app

查看:106
本文介绍了代表由应用程序发起的电话结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,使用以下代码拨打电话:

  //致电给定电话号码
- (void)callPhoneNumber:(NSString *)phoneNumber
{
if(!self.webview)
self.webview = [[UIWebView alloc] init];
self.webview.delegate = self;

//从电话号码中删除非数字
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@];

//调用
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@tel:%@,phoneNumber]];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:self.webview];
}

这是一个电话。我想要的是,我想知道用户何时结束通话。当用户结束通话时,我必须执行一个操作。有没有办法?



我试过的是将当前控制器的 webview 的委托。但是没有一个代理方法被调用。

   - (void)webViewDidStartLoad:(UIWebView *)webView 
{
DLog(@开始加载);
}

- (void)webViewDidFinishLoad :( UIWebView *)webView
{
DLog(@Finish Loading);


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误
{
DLog(@失败,错误:% @,错误);
}

我不知道你是否需要这个信息,但是我使用webview,以便当电话进行时,流量保持在应用程序内,在通话结束时,显示应用程序屏幕,而不是用户手动从本地联系人应用程序进入应用程序。

解决方案 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.

这篇关于代表由应用程序发起的电话结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆