问题
I am trying to get Call events (call received, call ended etc) I tried to run sample code of CoreTelephonyDemo, but I am not getting any call events. Can anybody guide me for the same.
I tried this code in applicationWillResignActive but I am not getting any events. Am I missing anything or doing anything wrong? Please guide .
- (void)applicationWillResignActive:(UIApplication *)application
{
CTCallCenter *callCenter1 = [[CTCallCenter alloc] init];
callCenter1.callEventHandler=^(CTCall* call)
{
if (call.callState == CTCallStateDisconnected)
{
NSLog(@"Call has been disconnected");
}
else if (call.callState == CTCallStateConnected)
{
NSLog(@"Call has just been connected");
}
else if(call.callState == CTCallStateConnected)
{
NSLog(@"Call is incoming");
}
else
{
NSLog(@"None of the conditions");
}
};
}
回答1:
You can detect call events. Your application delegate will receive calls to various UIApplicationDelegate
protocol methods when various events happen. One of these is the - (void)applicationWillResignActive:(UIApplication *)
application method, which is called for incoming calls or text messages, but could be called for other reasons as well.
You can detect a call only if your app is running in the foreground.
If your app will fall in any of the background running categories (VOIP, AUDIO, Location tracking or accessory ) you might be able to use the CTCallCenter
in the background. But be aware that Apple will reject you app if you miss use the background running mode for something it was not meant for.
The CTCallCenter
will allow you to detect any calls that are started or already in progress.
However you will not be able to detect any detail about the call, the CTCall
identifying the call will only tell you this state. The callID of CTCall
will just give you an unique identifier for the call but not the number being called.
来源:https://stackoverflow.com/questions/19383222/call-events-in-iphone