Detecting the call events in ios
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.
Detect call events in iOS?
- Yes this class is available in iOS 10.
- No, you can only detect a phone call while in the foreground.
- No, this is not really possible, you might be able to start recording sound but only the user mic.
iOS How to detect call state in background?
Finally, I solved it! I used code from this answer: Find if user is in a call or not?
I removed everything from AppDelegate
, all job is done in ViewController
:
override func viewDidLoad()
{
super.viewDidLoad()
NotificationCenter.default.addObserver(
self,
selector: #selector(cameBackFromSleep),
name: NSNotification.Name.UIApplicationDidBecomeActive,
object: nil
)
...
}
private func isOnPhoneCall() -> Bool
{
let callCntr = CTCallCenter()
if let calls = callCntr.currentCalls
{
for call in calls
{
if call.callState == CTCallStateConnected || call.callState == CTCallStateDialing || call.callState == CTCallStateIncoming
{
print("In call")
return true
}
}
}
print("No calls")
return false
}
func cameBackFromSleep()
{
self.viewWillAppear(true)
}
override func viewWillAppear(_ animated: Bool)
{
print("is on call", isOnPhoneCall())
switch isOnPhoneCall()
{
case true:
print("startBtnAnimation")
startBtnAnimation()
recordBtnIsPressed = true
case false:
print("stopBtnAnimation")
stopBtnAnimation()
recordBtnIsPressed = false
default: break
}
}
Now it works fine. Not sure why CTCallCenter
works so weird in AppDelegate
.
Detecting GSM Call States in IOS 10 (Swift 3, Xcode 8) and Notification from Background state
After a long while it looks like this may not be feasible in iOS 10. I did try using the background modes as suggested but neither i need to play music nor keep tracking the location at all times hence they do not work out for me.
I cannot use Push Kit
because the intent is to get events for normal GSM calls and not voip calls.
How to detect programmatically that call is on hold in iOS?
We can use CallKit Framework to get the Call Hold event.
We need to conform to CXCallObserver Delegate
[_callObserver setDelegate:self queue:nil];
where _callObserver is the instance of my CXCallObserver class
- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
if (call.isOnHold == true) {
NSLog(@"Call is on hold");
}
}
Get event for incoming call when application in background
Finally i managed it. there was an issue with my background GPS tracking functionality implementation, i have correct it and my code works like charm. So confirming that we can track call when application is in background.
Related Topics
Determine on Iphone If User Has Enabled Push Notifications
Uiactivityviewcontroller Crashing on iOS 8 Ipads
Create Thread Safe Array in Swift
Why Nsuserdefaults Failed to Save Nsmutabledictionary in Ios
How to Load Storyboard Programmatically from Class
How to Parse Json Response from Alamofire API in Swift
Save Custom Objects into Nsuserdefaults
How to Use Facebook iOS Sdk on iOS 10
How to Create Local Notifications
How to Use Protocol as Associatedtype in Another Protocol in Swift
How to Compress of Reduce the Size of an Image Before Uploading to Parse as Pffile? (Swift)
Execute Action When Back Bar Button of Uinavigationcontroller Is Pressed
How to Segue Programmatically in iOS Using Swift
String Replacement in Objective-C
Reloaddata() of Uitableview With Dynamic Cell Heights Causes Jumpy Scrolling
How to Detect Orientation Change