Call events in iPhone

为君一笑 提交于 2019-12-22 01:31:42

问题


I am trying to get Call events (call received, call ended etc) I tried to run sample code of CoreTelephonyDemo, but I am not getting any call events. Can anybody guide me for the same.

I tried this code in applicationWillResignActive but I am not getting any events. Am I missing anything or doing anything wrong? Please guide .

- (void)applicationWillResignActive:(UIApplication *)application
{
   CTCallCenter *callCenter1 = [[CTCallCenter alloc] init];
    callCenter1.callEventHandler=^(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 == CTCallStateConnected)
        {
            NSLog(@"Call is incoming");
        }
        else
        {
            NSLog(@"None of the conditions");
        }
    };
}

回答1:


You can detect call events. Your application delegate will receive calls to various UIApplicationDelegate protocol methods when various events happen. One of these is the - (void)applicationWillResignActive:(UIApplication *)application method, which is called for incoming calls or text messages, but could be called for other reasons as well.

You can detect a call only if your app is running in the foreground.

If your app will fall in any of the background running categories (VOIP, AUDIO, Location tracking or accessory ) you might be able to use the CTCallCenter in the background. But be aware that Apple will reject you app if you miss use the background running mode for something it was not meant for.

The CTCallCenter will allow you to detect any calls that are started or already in progress.

However you will not be able to detect any detail about the call, the CTCall identifying the call will only tell you this state. The callID of CTCall will just give you an unique identifier for the call but not the number being called.



来源:https://stackoverflow.com/questions/19383222/call-events-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!