How can I get the callers phone number from an incoming call on iphone

♀尐吖头ヾ 提交于 2019-12-07 18:35:28

问题


Hi I want to build an app that does something when an incoming call comes in. But I think that the phone needs to be jailbroken on the iphone to access the class that does that. I want to do it without the phone being jailbroken.


回答1:


Not possible.

However you may get the information like call state(connected/disconnected etc) using CoreTelephony framework.




回答2:


If you want to do anything when a call come or going then you have to use this code:

CTCallCenter *callCenter; //make it ivar if you are using ARC or handler will be auto-released...
callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call) {
    NSLog(@"Call id:%@", call.callID);
    [self callStateChange:call.callState andId:call.callID];
    if (call.callState==CTCallStateDialing) {
       NSLog(@"Call state:dialing");
    }
    if (call.callState==CTCallStateIncoming) {
       NSLog(@"Call state:incoming");
       //here you lower your speaking volume if you want
    }
    if (call.callState==CTCallStateConnected) {
       NSLog(@"Call state:connected");
    }
    if (call.callState==CTCallStateDisconnected) {
       NSLog(@"Call state:disconnected");
    }
};

but that will work when u app will active or go background to foreground. If app will kill or suspended the that will not work. First you detect state of call and then show a local notification immediately. And when click on view details then show ur app again. But this is not approved by apple because it will send phone call in background. So it may be risky.



来源:https://stackoverflow.com/questions/5739424/how-can-i-get-the-callers-phone-number-from-an-incoming-call-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!