如果我从我的应用程序拨打电话,我无法检测到通话结束(状态 CallStateDisconnected)。但是,如果我在我的应用程序处于活动状态时接到电话,我可以检测到该状态。当从我的应用程序开始呼叫时,我还会收到两次或 3 次状态 CTCallStateDialing。它曾经在iOS5下工作,iOS6出现这个问题。
我的应用程序删除代码;
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]];
我还记录了应用程序状态,我得到了- (void)applicationDidBecomeActive:(UIApplication *)application
在我开始通话后,我去- (void)applicationDidEnterBackground:(UIApplication *)application
通话结束后返回- (void)applicationDidBecomeActive:(UIApplication *)application.
这很奇怪,DidBecomeActive
在调用之后和进入后台之前调用吗?