2011-06-29 40 views
1

我想爲越獄iphone(ios 4.0或更高版本)創建一個應用程序。我希望我的應用程序保持運行狀態,並且每當我的電話開始響鈴(針對來電)時,我的應用程序應該能夠捕獲該「呼入」事件,並基於該事件我可以執行一些功能,例如,降低揚聲器音量。使用核心電話捕獲傳入的Callevent?

任何人都可以引導我走向正確的方向,至於如何捕獲這樣的事件,或者如果它是在私有核心框架中可用?

回答

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以上

#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"); 
     } 
}; 
核心電話的公共部分的可用