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

吃可爱长大的小学妹 提交于 2019-12-06 05:28:18

Not possible.

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

ios

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.

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