仅对传入呼叫检测到CallStateDisconnected,而不是从我的应用程序进行的呼叫 [英] CallStateDisconnected only detected for incoming calls, not for calls made from my app

查看:90
本文介绍了仅对传入呼叫检测到CallStateDisconnected,而不是从我的应用程序进行的呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从我的应用程序拨打电话,我无法检测到呼叫结束(状态CallStateDisconnected)。但如果我的应用程序处于活动状态时接到电话,我可以检测到该状态。当我的应用程序启动调用时,我还会收到状态CTCallStateDialing两次或三次。
过去在iOS5下运行,iOS6出现了这个问题。



我的应用程序代码;

  self.callCenter = [[CTCallCenter alloc] init]; 
self.callCenter.callEventHandler = ^(CTCall * call){

//我们呼叫中心的状态发生了变化
NSDictionary * dict = [NSDictionary dictionaryWithObject:call.callState forKey:@callState]; // BREAKPOINT HERE

[[NSNotificationCenter defaultCenter] postNotificationName:@CTCallStateDidChangeobject:self userInfo:dict];

};

奇怪的是,如果我在callEventHandler块中放置断点并在调用完成后恢复执行,它一切正常,然后我正确地获得了CallStateDisconnected。



然后我在视图控制器中订阅通知并在收到时执行此代码:

   - (void)ctCallStateDidChange1:(NSNotification *)notification 
{
NSString * call = [[notification userInfo] objectForKey:@callState] ;


if([call isEqualToString:CTCallStateDisconnected])
{
NSLog(@呼叫已断开连接);

}
else if([call isEqualToString:CTCallStateDialing])
{

NSLog(@Call start);
}
else if([call isEqualToString:CTCallStateConnected])
{
NSLog(@Call just just connected);
}
else if([call isEqualToString:CTCallStateIncoming])
{
NSLog(@Call is incoming);
}
其他
{
NSLog(@无);
}

}



我从我的应用程序拨打这样的电话:

  UIWebView * callWebview = [[UIWebView alloc] init]; 
[self.view addSubview:callWebview];
NSURL * telURL = [NSURL URLWithString:number];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

我还记录了app状态,我得到 - (void)applicationDidBecomeActive :( UIApplication *)应用程序



我开始调用后,然后转到 - (void)applicationDidEnterBackground :( UIApplication * )应用程序



并且在调用结束后返回 - (void)applicationDidBecomeActive:(UIApplication *)application。



奇怪的是,在调用之后和之前调用 DidBecomeActive 这是来自iOS 5手机的日志:

  2012-12-02 22:00:00.252 TestPhone [2297:707] didFinishLaunchingWithOptions:
2012-12-02 22:00:00.352 TestPhone [2297:707] applicationDidBecomeActive:
2012-12-02 22:00:06.708 TestPhone [2297:707] applicationWillResignActive:
2012-12-02 22:00:10.582 TestPhone [2297:1c03]致电开始
2012- 12-02 22:00:11.016 TestPhone [2297:707] appl icationDidBecomeActive:
2012-12-02 22:00:12.536 TestPhone [2297:707] applicationWillResignActive:
2012-12-02 22:00:12.564 TestPhone [2297:707] applicationDidEnterBackground:
2012-12-02 22:00:36.543 TestPhone [2297:707] applicationWillEnterForeground:
2012-12-02 22:00:36.769 TestPhone [2297:707] applicationDidBecomeActive:
2012-12-02 22 :00:36.840 TestPhone [2297:2e07]呼叫已断开连接
2012-12-02 22:00:36.854 TestPhone [2297:707] applicationWillResignActive:
2012-12-02 22:00:49.885 TestPhone [2297:707] applicationDidBecomeActive:

这是来自iOS 6手机的日志:

  2012-12-03 06:27:55.401 TestPhone [7734:907] didFinishLaunchingWithOptions:
2012-12-03 06: 27:55.462 TestPhone [7734:907] applicationDidBecomeActive:
2012-12-03 06:28:01.396 TestPhone [7734:907] applicationWillResignActive:
2012-12-03 06:28:04.345 TestPhone [7734 :907] applicationDidBecomeActive:
2012-12-03 06 :28:04.401 TestPhone [7734:1803]呼叫开始
2012-12-03 06:28:05.824 TestPhone [7734:907] applicationWillResignActive:
2012-12-03 06:28:05.826 TestPhone [ 7734:907] applicationDidEnterBackground:
2012-12-03 06:28:17.318 TestPhone [7734:907] applicationWillEnterForeground:
2012-12-03 06:28:17.329 TestPhone [7734:907] applicationDidBecomeActive:

已断开连接消息刚刚消失。 (这不是答案,这是一个观察。)



这是我使用的代码。我用xib中的一个按钮在xcode中创建了一个单视图应用程序,这是我的整个UIViewController:

  - (void)viewDidLoad {
[super viewDidLoad];
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler = ^(CTCall * myCall){
NSString * call = myCall.callState;
if([call isEqualToString:CTCallStateDisconnected])
NSLog(@呼叫已断开连接);
else if([call isEqualToString:CTCallStateDialing])
NSLog(@Call start);
else if([call isEqualToString:CTCallStateConnected])
NSLog(@呼叫刚刚连接);
else if([call isEqualToString:CTCallStateIncoming])
NSLog(@Call is incoming);
else
NSLog(@无);
};
}

- (IBAction)callButtonPressed:(id)sender {
NSString * number = @tel:01234567890;
UIWebView * callWebview = [[UIWebView alloc] init];
callWebview.frame = self.view.frame;
[self.view addSubview:callWebview];
NSURL * telURL = [NSURL URLWithString:number];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
}
@end


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:

2012-12-02 22:00:00.252 TestPhone[2297:707] didFinishLaunchingWithOptions:
2012-12-02 22:00:00.352 TestPhone[2297:707] applicationDidBecomeActive:
2012-12-02 22:00:06.708 TestPhone[2297:707] applicationWillResignActive:
2012-12-02 22:00:10.582 TestPhone[2297:1c03] Call start
2012-12-02 22:00:11.016 TestPhone[2297:707] applicationDidBecomeActive:
2012-12-02 22:00:12.536 TestPhone[2297:707] applicationWillResignActive:
2012-12-02 22:00:12.564 TestPhone[2297:707] applicationDidEnterBackground:
2012-12-02 22:00:36.543 TestPhone[2297:707] applicationWillEnterForeground:
2012-12-02 22:00:36.769 TestPhone[2297:707] applicationDidBecomeActive:
2012-12-02 22:00:36.840 TestPhone[2297:2e07] Call has been disconnected
2012-12-02 22:00:36.854 TestPhone[2297:707] applicationWillResignActive:
2012-12-02 22:00:49.885 TestPhone[2297:707] applicationDidBecomeActive:

and here's the log from an iOS 6 phone:

2012-12-03 06:27:55.401 TestPhone[7734:907] didFinishLaunchingWithOptions:
2012-12-03 06:27:55.462 TestPhone[7734:907] applicationDidBecomeActive:
2012-12-03 06:28:01.396 TestPhone[7734:907] applicationWillResignActive:
2012-12-03 06:28:04.345 TestPhone[7734:907] applicationDidBecomeActive:
2012-12-03 06:28:04.401 TestPhone[7734:1803] Call start
2012-12-03 06:28:05.824 TestPhone[7734:907] applicationWillResignActive:
2012-12-03 06:28:05.826 TestPhone[7734:907] applicationDidEnterBackground:
2012-12-03 06:28:17.318 TestPhone[7734:907] applicationWillEnterForeground:
2012-12-03 06:28:17.329 TestPhone[7734:907] applicationDidBecomeActive:

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:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.callCenter = [[CTCallCenter alloc] init];
    self.callCenter.callEventHandler = ^(CTCall* myCall) {
        NSString *call = myCall.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");
    };
}

- (IBAction)callButtonPressed:(id)sender {
    NSString *number = @"tel:01234567890";
    UIWebView *callWebview = [[UIWebView alloc] init];
    callWebview.frame = self.view.frame;    
    [self.view addSubview:callWebview];
    NSURL *telURL = [NSURL URLWithString:number];
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
}
@end

这篇关于仅对传入呼叫检测到CallStateDisconnected,而不是从我的应用程序进行的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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