问题描述
我想查看用户是否正在使用该应用程序,并查看他们是否在通话中.我正在查看此链接,以查看用户是否正在打电话:.但是,这似乎是针对Objective-C的.我想知道是否有一个Swift等效项.这是我的尝试:
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.")
}
}
但是,看起来好像call没有属性.callState
,如上例所示.任何帮助,将不胜感激!谢谢!
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!
推荐答案
Swift 2.2的更新:您只需安全地解开currCall.currentCalls
.
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.")
}
}
}
这篇关于查找用户是否在通话中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!