识别iPhone中的来电号码 [英] Identify number of incoming call in iPhone

查看:258
本文介绍了识别iPhone中的来电号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道谁在给我打电话?
识别我的列表中的号码甚至联系人。

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];


推荐答案

您无权访问此信息公共SDK(越狱的iPhone是另一回事)。 Apple禁止应用访问与呼叫历史相关的任何信息。您上面发布的代码是这样您的应用可以检测到用户何时接到电话并相应地调整其界面,但就是这样。

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.

这篇关于识别iPhone中的来电号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆