Capture incoming Callevent using coretelephony?

2019-05-30 08:11发布

I want to create an application for jailbroken iphone (ios 4.0 or greater). I want my application to remain running and whenever my phone starts ringing (for an incoming call), my application should be able to capture that "call incoming" event and based on that i could perform some function e.g. lower speaker volume.

Can anyone guide me to the right direction, as to how can i capture such event, or if it is available in private coretelephony framework ?

1条回答
Explosion°爆炸
2楼-- · 2019-05-30 08:39

Are you sure you want to monitor calls and not use

- (void)applicationWillResignActive:(UIApplication *)application
{
/*
 Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
 */
}

which is even in default XCode4 template?

If you still want call monitoring - it's available in public part of Core Telephony on iOS 4+

#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>

....

CTCallCenter *callCenter;//make it ivar if you are using ARC or handler will be auto-released
..
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call)
{
    NSLog(@"Call id:%@", call.callID);

    [self callStateChange:call.callState andId:call.callID];
        if (call.callState==CTCallStateDialing)
        {
            NSLog(@"Call state:dialing");
        }
        if (call.callState==CTCallStateIncoming)
        {
            NSLog(@"Call state:incoming");
            //here you lower your speaking volume if you want
        }
        if (call.callState==CTCallStateConnected)
        {
            NSLog(@"Call state:connected");
        }
        if (call.callState==CTCallStateDisconnected)
        {
            NSLog(@"Call state:disconnected");
        }
};
查看更多
登录 后发表回答