我想为越狱iphone(ios 4.0或更高版本)创建一个应用程序。我希望我的应用程序继续运行,每当我的手机开始响铃时(对于来电),我的应用程序应该能够捕获“呼入”事件并基于我可以执行某些功能,例如降低扬声器音量。
任何人都可以指导我找到正确的方向,我如何捕获此类事件,或者是否可以在私有coretelephony框架中使用?
答案 0 :(得分:1)
您确定要监听来电而不是
- (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.
*/
}
哪个甚至是默认的XCode4模板?
如果您仍然需要呼叫监控 - 它可以在iOS 4 +上的Core Telephony的公共部分中使用
#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");
}
};