Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find if user is in a call or not?

I wanted to see if a user was using the application and to see if they were in a phone call or not. I was following this link to see check if a user was in a phone call or not: iOS How to check if currently on phone call. However, this looks like it's for Objective-C. I was wondering if there was a Swift equivalent for this. This is my attempt:

    var currCall = CTCallCenter()
    var call = CTCall()

    for call in currCall.currentCalls{
        if call.callState == CTCallStateConnected{
            println("In call.")
        }
    }

However, it doesn't seem as if call has an attribute .callState like how it does in the previous example. Any help would be appreciated! Thanks!

like image 597
user1871869 Avatar asked Nov 29 '22 01:11

user1871869


1 Answers

iOS 10, Swift 3

import CallKit

/**
    Returns whether or not the user is on a phone call
*/
private func isOnPhoneCall() -> Bool {
    for call in CXCallObserver().calls {
        if call.hasEnded == false {
            return true
        }
    }
    return false
}
like image 61
AlBeebe Avatar answered Dec 18 '22 11:12

AlBeebe