iphone开发在应用中监听(判断)来电状态-接听-拒接

phone开发在应用中监听(判断)来电状态-接听-拒接-CoreTelephony  
zxwo0o IOS,iphone,互联网络 CoreTelephony, CTCallCenter  
0  
Comments 发表评论  
当我们应用在使用中时如果突然来电话了,应用就被暂时推到后台去,有时我们需要些针对来点的处理。  
可以使用如下方法来判断:使用CoreTelephony框架  
#import  
01      
#import  
02      
 
03      
 
04      
CTCallCenter *callCenter = [[CTCallCenter alloc] init];  
05      
    callCenter.callEventHandler=^(CTCall* call){  
06      
 
07      
        if (call.callState == CTCallStateDialing){  
08      
            NSLog(@"Call Dialing");  
09      
        }  
10      
        if (call.callState == CTCallStateConnected){  
11      
            NSLog(@"Call Connected");  
12      
 
13      
            [self performSelectorOnMainThread:@selector(closeTalk) withObject:nil waitUntilDone:YES];  
14      
        }  
15      
        if (call.callState == CTCallStateDisconnected){  
16      
            [self performSelectorOnMainThread:@selector(closeTalk) withObject:nil waitUntilDone:YES];  
17      
            NSLog(@"Call Disconnected");  
18      
        }  
19      
    };  
20      
 
 
将如上代码添加到  
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
中即可,有通话事件就会跑进那个block里面执行。 

你可能感兴趣的:(常用的代码)