CallStateDisconnected only detected for incoming c

2019-01-18 22:30发布

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?

1条回答
混吃等死
2楼-- · 2019-01-18 23:06

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
查看更多
登录 后发表回答