如何使用 iOS Callkit 模拟拨出电话

How can I simulate an Outgoing call using iOS Callkit

我已经阅读了iOS CallKit文档,下面是Apple在'Making Outgoing Calls'部分提供的代码。当我尝试调用函数 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.