使用iOS中的CTCallCenter检测呼叫状态

时间:2014-12-04 10:09:07

标签: ios objective-c iphone

以下代码可以正常工作以在iPhone 4s(运行iOS 5.1.1)中获取应用程序中的呼叫状态,但不能在iPhone 5s(运行iOS 7.1.2)中运行。可以帮助任何人吗?

在MyViewController.h中

@property (nonatomic, strong) CTCallCenter* callCenter;

在MyViewController.m

- (void)viewDidLoad
{
    [self registerForCalls];
}

- (void) registerForCalls {

    self.callCenter = [[CTCallCenter alloc] init];

    [callCenter setCallEventHandler: ^(CTCall* call) {
        if (call.callState == CTCallStateDisconnected)
        {
            NSLog(@"Call has been disconnected");
        }
        else if (call.callState == CTCallStateConnected)
        {
            NSLog(@"Call has just been connected");
        }
        else if (call.callState == CTCallStateIncoming)
        {
            NSLog(@"Call is incoming");
        }
        else if (call.callState == CTCallStateDialing)
        {
            NSLog(@"Call is Dialing");
        }
        else
        {
            NSLog(@"None of the conditions");
        }
    }];
}

0 个答案:

没有答案