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.
Not possible.
However you may get the information like call state(connected/disconnected etc) using CoreTelephony framework.
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