I am new to ios. I was wondering if there is any way to detect the call events like incoming call, outgoing call even if my app is not in foreground. And if yes it is possible then can i read the details about that call like duration, whether it is missed, dialed or recieved. Thanks in advance.
Yes you can detect a Call. but only if your app is running in the foreground.
For this you can use the Core Telephony Framework.
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.
Related
I'm trying to make an iOS app that can programmatically make a phone call silently, blocking any kind of outgoing phone call sound. (After the phone call is ready the app would then start recording the audio from the microphone.) Does anyone know if that's possible or have any idea about how that can be done?
Apple is really protective in such core features as calls. So we as a programmers have really narrow API to use. Basically, to make a call you have two options:
Open URL with format like tel://
Init call with instance of CXStartCallAction
Everything happens after is held by the system, so you don't have much of control over it. To be concrete, you have no control over call sounds.
You can have much more control, if you use VoIP or something similar.
Welcome Antonio!
Briefly, no you can not.
Let me explain further...
After the recipient answers the call, the system calls the provider
delegate’s provider(_:perform:) method. In your implementation of that
method, configure an AVAudioSession and call the fulfill() method on
the action object when finished.
You may have some doing to configure audio session but the system would block the microphone and from the API side you will not have access whatsoever.
I am deeply sorry for being so blunt, but what you're intending is simply no possible.
Please let me clear, is it possible to integrate CallKit without using VOIP?
What I want to achieve is to get call history from iPhone. and I know it is not possible. So I want to create my own history with the help of CallKit. For this purpose I need following:
I want to detect incoming call (not voip)
Outgoing call (not voip)
In all states - background, foreground, not running, suspended
Call duration
Can we do this with the help of CallKit or is there any other workaround?
Note: It is not about VOIP Apps
is it possible to integrate CallKit without using VOIP?
I would say yes, SpeakerBox (the Apple CallKit example) doesn't use VoIP.
https://developer.apple.com/library/archive/samplecode/Speakerbox/Listings/Speakerbox_SpeakerboxCall_swift.html
is it possible to integrate CallKit in all states - background, foreground, not running, suspended without using VOIP?
No, if the app is suspended or not running you can't detect an incoming call.
For case of CallDuration in active mode can be traceable by using callkit. Let me know, if you are only interested to know Call Duration. I can give full detail.
Other all cases that you mentioned are not possible to trace, unless your phone is jailbroken.
I'm using AVAudioSession in my VOIP app (using also CallKit).
I understand that the session can get interrupted by a number of things, for example by a second incoming call.
Apple states towards the bottom of this page:
https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html#//apple_ref/doc/uid/TP40007875-CH4-SW5
"Note: There is no guarantee that a begin interruption will have a
corresponding end interruption. Your app needs to be aware of a switch
to a foreground running state or the user pressing a Play button. In
either case, determine whether your app should reactivate its audio
session."
On the mentioned page there is an example for a special case, when the user ignores the incoming call and in that case AVAudioSessionInterruptionTypeEnded is being sent.
But what should I do to know when the interruption has ended in every other case (in which cases I will never receive an AVAudioSessionInterruptionTypeEnded)? (E.g. When the user answers the 2nd call and puts me on hold and later he ends the 2nd call?)
Thanks!
I remember when you use CallKit, no app using audio like music will interrupt your app except for those other voip apps or native calls.
In that case, your call will be ended/held according to your response on the call kit ui (If your call do not support held, you will not be shown a thid button accept&hold)----Then, you can get your callback from CallKit delegate methods.
The Interruption api just works when CallKit is not used and CallKit app have a higher priority on audio session than those not using it.
When my application is in the foreground it needs to easily detect the call event like call connected, call disconnected but when my application goes into background it does not detect any call events.
So how can I detect call events like incoming call and outgoing call in background?
I am working on CallKit framework with iOS 10 and XCode 8. I found that core telephony framework has been deprecated in iOS 10.
I am using the CXCallObserverDelegate Pattern for observing the call.
I want to calculate the call duration of incoming and outgoing calls during calling.
After searching about this question i ended up with this answer i think might help
Yes, you can detect a Call, but only if your app is running in the foreground.
For this you can use the Core Telephony Framework.
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 your app if you 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.
original question
How does Truecaller intercept incoming phonecalls on the iphone to display caller ID?
I didn't think this was possible from within the app?
Specifically, if I wanted to build this functionality, what protocols would I go about using?
http://www.truecaller.com/how-it-works
On an iPhone, without jailbreaking it:
- you cannot intercept a call in any way
- you cannot determine the phone number nor the caller ID identifying information regarding the call. Even if you could there
is no way to alter what is displayed on the call screen
- you cannot block the call
- your program can get a notification when a call is being made/terminated etc. But only if your app is executing in the
foreground at the time of the call or if the app is in the
background and has a relevant background mode (even then you can
only know there is a call in some circumstance, depending upon what
you're doing in the background and what state your in etc. Its too complex to describe the exact situation here briefly)
True Caller doesn't do that on iOS as it isn't supported with the native SDK. See their FAQ:
http://www.truecaller.com/support , specifically the "Why don't I receive live caller ID?" Section under "iPhone/Windows Phone". If you must though, try looking into a solution for jailbroken devices.
It's impossible to "intercept" calls. It is possible to handle the "background event call" when a iPhone get's a call. That said, Truecaller doesn't intercept calls. More info can be found on their website.