我正在使用以下代码来测试CallKit。我可以从“ A”设备调用去电,并通过使用VoIP接收UUID来调用“ B”设备上的呼入功能。但是,当我按“ B”上的接听电话按钮时,没有声音(“ A”和“ B”)出现。我没有在“ A”上收到任何委托回调,以了解另一边的任何操作。
我怎么知道“ B”设备的回叫状态是“ A”设备上的应答,拒绝,保持或结束通话?
是使用VoIP方法来通知设备“ A”还是缺少步骤?
import Foundation
import CallKit
class ProviderDelegate: NSObject, CXProviderDelegate {
static let sharedInstance = ProviderDelegate()
var provider: CXProvider!
var controller: CXCallController!
override init() {
controller = CXCallController()
let providerConfiguration = CXProviderConfiguration(localizedName: "My App name")
providerConfiguration.supportsVideo = true
providerConfiguration.maximumCallsPerCallGroup = 1
providerConfiguration.supportedHandleTypes = [.generic]
provider = CXProvider(configuration: providerConfiguration)
super.init()
provider.setDelegate(self, queue: nil)
}
func incomingCall(uuid: UUID) {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: "Any name")
provider.reportNewIncomingCall(with: uuid, update: update, completion: { error in })
}
func outgoingCall(uuid: UUID) {
let transaction = CXTransaction(action: CXStartCallAction(call: uuid, handle: CXHandle(type: .generic, value: "Any name")))
controller.request(transaction, completion: { error in })
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
print ("CXAnswerCallAction")
configureAudioSession()
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
print ("CXEndCallAction")
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
print ("CXSetHeldCallAction")
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
print ("CXStartCallAction")
configureAudioSession()
provider.reportOutgoingCall(with: action.uuid, startedConnectingAt: nil)
provider.reportOutgoingCall(with: action.uuid, connectedAt: nil)
action.fulfill()
}
func providerDidReset(_ provider: CXProvider) {
print ("Distory")
}
}
import Foundation
import AVFoundation
func configureAudioSession() {
print("Configuring audio session")
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.setMode(AVAudioSessionModeVoiceChat)
try session.setActive(true)
}
catch (let error) {
print("Error while configuring audio session: \(error)")
}
}
func startAudio() {
print("Starting audio")
}
func stopAudio() {
print("Stopping audio")
}
使用Apple原生VOIP服务发送和接收UUID
let providerDelegate = ProviderDelegate.sharedInstance
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
let payloadDict = payload.dictionaryPayload["aps"] as! NSDictionary
let uuid = payloadDict.object(forKey: "uuid") as! String
providerDelegate.incomingCall(uuid: UUID.init(uuidString: uuid)!)
}