2012-01-24 47 views
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]; 
+0

可能重複[以編程方式獲取來電號碼](http://stackoverflow.com/questions/4003791/programmatically-get-the-number-of-the-incoming-call) –

回答

2

您無權訪問公共SDK中的此信息(越獄iPhone是另一回事)。 Apple禁止應用程序訪問有關通話記錄的任何任何信息。您上面發佈的代碼是,您的應用可以檢測用戶何時接到電話並相應地調整其界面,但就是這樣。