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!
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With