我如何知道谁在给我打电话? 确定我的列表中的数字甚至联系人。
我可以使用此代码识别是否有电话。
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 :(得分:2)
您无法在公共SDK中访问此信息(越狱的iPhone是另一回事)。 Apple禁止应用访问与呼叫历史相关的任何信息。您上面发布的代码是这样您的应用可以检测到用户何时接到电话并相应地调整其界面,但就是这样。