Capture incoming Callevent using coretelephony?

假装没事ソ 提交于 2020-01-14 04:39:08

问题


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:


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


来源:https://stackoverflow.com/questions/6519902/capture-incoming-callevent-using-coretelephony

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