iphone - CallStateDisconnected仅检测到拨入呼叫,而不是针对我的应用程序发出的呼叫

  显示原文与译文双语对照的内容
0 0

我不能检测调用的结束( 状态CallStateDisconnected ) 假如我做电话我的app 。 但是如果我接收调用my app处于活动状态时,我可以检测到该状态。 我也接收状态CTCallStateDialing两次或者3 次调用启动时从我的应用程序。 它曾经是工作与iOS6 iOS5下,此问题出现。

我的app del代码;

 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]; 

};

奇怪的是它究竟是如何工作的,如果我把断点放在callEventHandler块并继续执行调用结束后,那时我就有CallStateDisconnected正确。

然后我订阅通知在我看来控制器并执行此代码当我收到它们:

- (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");
}

}

我自己从我的应用中调用如下所示:

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

我也记录app状态和得到 - (void)applicationDidBecomeActive:(UIApplication *)application

我start调用后,然后我去 - (void)applicationDidEnterBackground:(UIApplication *)application

并在调用完成后回 - (void)applicationDidBecomeActive:(UIApplication *)application.

是那个奇怪的, DidBecomeActive后调用之前调用由和去背景?

时间: 原作者:

0 0

下面是日志从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] 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:

这是日志从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] 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:

" 断开" 消息刚刚消失了。 ( 这不是答案,是个人意见) 。

这是我以前的代码。 我我创建了一个single view application Xcode中通过按钮在xib中,这是我的整个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
原作者:
...