在iPhone中调用事件 [英] Call events in iPhone

查看:99
本文介绍了在iPhone中调用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取呼叫事件(呼叫接收,呼叫结束等)
我试图运行CoreTelephonyDemo的示例代码,但我没有收到任何呼叫事件。
任何人都可以指导我。

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.

我在applicationWillResignActive中尝试了这段代码,但我没有收到任何事件。我错过了什么或做错了吗?请指导。

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


推荐答案

您可以检测呼叫事件。当各种事件发生时,您的应用程序委托将接收对各种 UIApplicationDelegate 协议方法的调用。其中一个是 - (void)applicationWillResignActive:(UIApplication *)应用程序方法,它被调用来电或短信,但也可以出于其他原因调用。

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.

如果您的应用程序属于任何后台运行类别(VOIP,音频,位置跟踪或附件),您可以使用 CTCallCenter 在后台。但要注意,如果你错过了使用后台运行模式的话,Apple会拒绝你的应用程序。

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.

CTCallCenter 将允许您检测已启动或正在进行的任何呼叫。

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

但是,您将无法检测到有关呼叫的任何详细信息, CTCall 识别呼叫只会告诉你这种状态。 CTCall 的callID只会为您提供呼叫的唯一标识符,但不会为您调用该号码。

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.

这篇关于在iPhone中调用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆