How do I know who is calling me? Identify the number or even the contact in my list case I have.
I can identify if have or not a call, with this code.
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];