0
我如何知道誰在給我打電話? 識別我的列表案例中的號碼,甚至是聯繫人。識別iPhone中的來電號碼
我可以通過此代碼識別是否有呼叫。
void (^ctCallStateMuda)(NSNotification *) = ^(NSNotification * notification) {
NSString *callInfo = [[notification userInfo] objectForKey:@"callState"];
if ([callInfo isEqualToString:CTCallStateIncoming]) {
NSLog(@">>>>>> chegando");
} else if ([callInfo isEqualToString:CTCallStateConnected]) {
NSLog(@">>> atendendo <<<");
} else if ([callInfo isEqualToString:CTCallStateDisconnected]) {
NSLog(@"desconectado >>>>>>");
} else if ([callInfo isEqualToString:CTCallStateConnected]) {
NSLog(@"discando");
} else {
NSLog(@"nada");
}
};
CTCallCenter *callCenter;
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler = ^(CTCall* aCallIncomming) {
NSDictionary *dict = [NSDictionary dictionaryWithObject:aCallIncomming.callState
forKey:@"callState"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CTCallStateDidChange"
object:self
userInfo:dict];
};
[[NSNotificationCenter defaultCenter] addObserverForName:@"CTCallStateDidChange"
object:nil
queue:nil
usingBlock:ctCallStateMuda];
可能重複[以編程方式獲取來電號碼](http://stackoverflow.com/questions/4003791/programmatically-get-the-number-of-the-incoming-call) –