我已经浏览了iOS CallKit文档,以下是Apple在"拨打电话"部分下提供的代码。当我尝试调用函数startOutGoingCall()时,没有任何反应,即我没有看到任何传出调用UI。
有人可以建议我如何触发本机传出呼叫 UI。
func startOutGoingCall(){
let uuid = UUID()
let handle = CXHandle(type: .emailAddress, value: "jappleseed@apple.com")
let startCallAction = CXStartCallAction(call: uuid)
startCallAction.destination = handle
let transaction = CXTransaction(action: startCallAction)
callController.request(transaction) { error in
if let error = error {
print("Error requesting transaction: (error)")
} else {
print("Requested transaction successfully")
}
}
}
编辑:从我的代码中添加了委托方法
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
logMessage(messageText: "provider:performStartCallAction:")
/*
* Configure the audio session, but do not start call audio here, since it must be done once
* the audio session has been activated by the system after having its priority elevated.
*/
localMedia?.audioController.configureAudioSession(.videoChatSpeaker)
callKitProvider.reportOutgoingCall(with: action.callUUID, startedConnectingAt: nil)
performRoomConnect(uuid: action.callUUID, roomName: action.handle.value) { (success) in
if (success) {
provider.reportOutgoingCall(with: action.callUUID, connectedAt: Date())
action.fulfill()
} else {
action.fail()
}
}
}
没有从 CallKit 获得的传出 UI。当你拨打传出电话时,你的应用处于打开状态,因此,你的应用应显示 UI。