iOS 5 - CTCallCenter不适合我 [英] iOS 5 - CTCallCenter not working for me

查看:93
本文介绍了iOS 5 - CTCallCenter不适合我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的手机:iOS 5.1.1越狱使用Absynth2

My phone: iOS 5.1.1 Jailbroken using Absynth2

我正在尝试做什么:
检测来电或何时正在拨打电话...

好的,这是我放在 AppDelegate 内的代码在 didEnterBackground 下,也尝试在 didResignActive - 我没有得到任何错误,但我也没有得到任何结果..

Okay here is my code that i placed inside the AppDelegate under didEnterBackground, also tried in didResignActive - i don't get any errors but i also don't get any results..

callCenter = [[CTCallCenter alloc] init];   
[callCenter setCallEventHandler:^(CTCall *call) {
    NSDictionary *dict = [NSDictionary dictionaryWithObject:call.callState forKey:@"callState"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CTCallStateDidChange" object:nil userInfo:dict];
    NSLog(@"state changed on call: %@", call);
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callDial:) name:CTCallStateDialing object:nil];

任何帮助表示赞赏。谢谢!

any help is appreciated. thanks!

推荐答案

问题是iOS显然没有在后台向UIApplications发送通知。来自 CTCallCenter的iOS文档

The problem is that iOS apparently doesn't deliver the notifications to UIApplications in the background. From the iOS documentation for CTCallCenter:


如果您的应用程序在发生调用事件时处于活动状态,
系统会立即将事件调度给您的处理程序。但是,在您的申请被暂停时,也可以拨打
事件。虽然
暂停,但你的申请不会收到来电事件。

If your application is active when a call event takes place, the system dispatches the event to your handler immediately. However, call events can also take place while your application is suspended. While it is suspended, your application does not receive call events.

既然你已经越狱了,为什么不让你的 app一个启动守护程序?然后,它可以作为服务一直运行。如果你这样做,那么下面的代码应该收到你的通知(我在越狱的iOS 5.0.1 iPhone 4上测试过):

Since you are jailbroken, why not make your "app" a launch daemon? Then, it can run all the time as a service. If you do this, then the following code should get your notifications (I tested this on a jailbroken iOS 5.0.1 iPhone 4):

@property (nonatomic, strong) CTCallCenter* callCenter;

并注册以下通知:

- (void) registerForCalls {

    self.callCenter = [[CTCallCenter alloc] init];
    NSLog(@"registering for call center events");
    [callCenter setCallEventHandler: ^(CTCall* call) {
        if ([call.callState isEqualToString: CTCallStateConnected]) {

        } else if ([call.callState isEqualToString: CTCallStateDialing]) {

        } else if ([call.callState isEqualToString: CTCallStateDisconnected]) {

        } else if ([call.callState isEqualToString: CTCallStateIncoming]) {

        }
        NSLog(@"\n\n callEventHandler: %@ \n\n", call.callState);
    }];
}

这是关于如何创建Launch Daemons 的好教程,如果你以前没有这样做过。

Here's a good tutorial on how to create Launch Daemons, if you haven't done that before.

如果您的应用程序也有图形组件,那么您可以构建两个部分:始终运行的启动守护程序以及用户启动它时运行的UI应用程序。如果需要,他们可以通过通知相互沟通。

If you also have a graphical component to your app, then you can build two parts: the launch daemon to run all the time, and the UI app that runs when the user launches it. They can communicate with each other with notifications, if need be.

这篇关于iOS 5 - CTCallCenter不适合我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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