我无法检测到的呼叫(州CallStateDisconnected)的结束,如果我从我的应用程序调用。 但是,如果我收到来电时我的应用程序是活动的,我可检测状态。 我也收到状态CTCallStateDialing两倍或3倍时调用从我的应用程序启动。 它使用的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
调用进行才去背景后,叫什么名字?
下面是从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:
该“断开”消息刚刚消失。 (这不是一个答案,这是一个观察)。
下面是我使用的代码。 II创造了在厦门国际银行一个按钮在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(@"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 only detected for incoming calls, not for calls made from my app