Find If User Is in a Call or Not

Find if user is in a call or not?

Update for Swift 2.2: you just have to safely unwrap currCall.currentCalls.

import CoreTelephony
let currCall = CTCallCenter()

if let calls = currCall.currentCalls {
for call in calls {
if call.callState == CTCallStateConnected {
print("In call.")

Previous answer: you need to safely unwrap and to tell what type it is, the compiler doesn't know.

import CoreTelephony
let currCall = CTCallCenter()

if let calls = currCall.currentCalls as? Set<CTCall> {
for call in calls {
if call.callState == CTCallStateConnected {
println("In call.")

Swift / phone call / check if user wants to call

As answered by User maddy, telprompt did the trick.

@IBAction func phoneButtonAction(sender: AnyObject) {

let phone = "telprompt://123456789"
let url:NSURL = NSURL(string:phone)!

iOS How to check if currently on phone call

The CTCallCenter object has a currentCalls property which is an NSSet of the current calls. If there is a call then the currentCalls property should be != nil.

If you want to know if any of the calls is actually connected, then you'll have to iterate through the current calls and check the callState to determine if it is CTCallStateConnected or not.

android how to find if a person is in call or no?

As far as I Know, it is not possible to have command in the ongoing call and also to automatically disconnect a call. Telephone API doesn't provide any methods to do any of changes while person is talking with someone.

How can I find out whether the user pressed the Call or the Cancel button when making a call from my app?

This isn't perfect, but you could identify that "call" was pressed instead of "cancel" by listening for the UIApplicationSuspendedNotification (you'd have to add some logic to ignore this event when someone pushed the 'home' key, or was accepting an incoming call... maybe by adding/removing the observer around the logic where the phone number is being presented):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(suspended:) name:@"UIApplicationSuspendedNotification" object:nil];

-(void)suspended:(NSNotification *) notification

Detecting if user has in call status bar

UIApplicationDelegate has these two methods.

// ObjC
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame; // in screen coordinates
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame;

// Swift
func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect)
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect)

And there are Notifications too.


// Swift

but they're not posted on the launch of the app, so I wouldn't recommend it.

The simulator has an useful tool to test that.

Hardware->Toggle In-Call Status Bar (⌘Y)

I would suggest you to implement those methods on your AppDelegate file. They will be called when the status bar change it's height. One of them it's called before and the other after the change.

Assuming you want that your ViewController to be notified when the change occurs, one option, is to send notifications. Like this

First, add this property/variable on AppDelegate

// ObjC
@property (assign, nonatomic) CGRect currentStatusBarFrame;

// Swift
var currentStatusBarFrame: CGRect = .zero

then, implement willChangeStatusBarFrame

// ObjC
- (void) application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
self.currentStatusBarFrame = newStatusBarFrame;
[[NSNotificationCenter defaultCenter] postNotificationName:@"Status Bar Frame Change"
userInfo:@{@"current status bar frame": [NSValue valueWithCGRect:newStatusBarFrame]}];


// Swift
func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) {
currentStatusBarFrame = newStatusBarFrame
name: NSNotification.Name(rawValue: "Status Bar Frame Change"),
object: self,
userInfo: ["current status bar frame": newStatusBarFrame])

And we're done with the base of our Status Bar Frame Checker. The next part you implement on any ViewController that needs to know the status bar frame.

Any time you want to get the status bar frame, you do like so

// ObjC
[(AppDelegate*)[[UIApplication sharedApplication] delegate] currentStatusBarFrame]

// Swift
(UIApplication.shared.delegate as! AppDelegate).currentStatusBarFrame

And to be notified when it changes, add this to ViewDidLoad method.

In ObjC

[[NSNotificationCenter defaultCenter] addObserver:self
name:@"Status Bar Frame Change"
object:[[UIApplication sharedApplication] delegate]];

And implement this method

- (void) statusBarFrameChanged:(NSNotification*)notification
CGRect newFrame = [[notification.userInfo objectForKey:@"current status bar frame"] CGRectValue];
NSLog(@"new height %f", CGRectGetHeight(newFrame));

In Swift

    NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "Status Bar Frame Change"),
object: nil,
queue: nil) { (note) in
guard let currentStatusBarFrame = note.userInfo?["current status bar frame"] as? CGRect else {return}
print("New Height", currentStatusBarFrame.height)

Related Topics

Leave a reply