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.
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;
and register for notifications with:
- (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(@"
callEventHandler: %@
", call.callState);
}];
}
Here's a good tutorial on how to create Launch Daemons, if you haven't done that before.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…