0

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];
Loko Varrido
  • 65
  • 10
  • possible duplicate of [Programmatically get the number of the incoming call](http://stackoverflow.com/questions/4003791/programmatically-get-the-number-of-the-incoming-call) – jscs Jan 24 '12 at 18:56

1 Answers1

2

You don't have access to this information in the public SDK (a jailbroken iPhone is another matter). Apple prohibit apps from having access to any information relating to call history. The code you've posted above is so your app can detect when the user is receiving a phone call and adapt their interface accordingly, but that's it.

lxt
  • 31,146
  • 5
  • 78
  • 83