当应用关闭时,Swift Callkit可以与调用方和接收方进行通信

时间:2018-09-28 08:22:18

标签: ios swift callkit pushkit

我一直在尝试使用callkit和pushkit制作VoIP应用。当呼叫者单击呼叫按钮时,接收者会收到带有Pushkit的来电屏幕,呼叫者会转到呼叫屏幕并等待接收者的应答。
我需要的是当呼叫者取消呼叫时,需要在接听或拒绝之前关闭接收者用户的屏幕。但是,当接收者单击“接听”或“拒绝”按钮时,呼叫者屏幕顶部的绿色条仍没有响应,仍显示“返回呼叫”。但是它需要启动计时器或根据接收者的答案自动关闭。
这是我的发送呼叫功能。 (我的提供商全局变量)

_provider = CXProvider(configuration: CXProviderConfiguration(localizedName: "app"))
    _provider.setDelegate(self, queue: nil)
let controller = CXCallController()
let transaction = CXTransaction(action: CXStartCallAction(call: uuid, handle: CXHandle(type: .generic, value: "Pete Za")))
controller.request(transaction, completion: { error in })

let vc = CallRoomViewController()
vc.modalPresentationStyle = .overFullScreen
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true)

我的AppDelegate pushRegistry函数。

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {

    print("PushType: \(type)")
    print("---PushPayload---")

    let json = payload.dictionaryPayload as NSDictionary
    print(payload.dictionaryPayload as NSDictionary)
    let aps = json["aps"] as! NSDictionary
    let callerId = aps["callerId"] as! String
    let callerImg = aps["callerImg"] as! String
    let callerName = aps["callerName"] as! String
    let receiverId = aps["receiverId"] as! String
    let receiverImg = aps["receiverImg"] as! String
    let receiverName = aps["receiverName"] as! String
    let roomNo = aps["roomNo"] as! String
    let token = aps["token"] as! String
    let uuidstr = aps["uuid"] as! String
    let uuid = UUID(uuidString: uuidstr) as! UUID


    let config = CXProviderConfiguration(localizedName: "app")
    config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "speaker")!)
    config.ringtoneSound = "ringing.mp3"
    config.supportsVideo = false;
    _provider = CXProvider(configuration: config)
    _provider.setDelegate(self, queue: nil)
    let update = CXCallUpdate()
    update.remoteHandle = CXHandle(type: .generic, value: callerName)
    update.hasVideo = false
    _provider.reportNewIncomingCall(with: uuid, update: update, completion: { error in })

  }

提供者委托方法:

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    action.fulfill()

    let vc = CallRoomViewController()
    self.window?.rootViewController = vc
    self.window?.makeKeyAndVisible()
  }

  func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
    action.fulfill()

  }

0 个答案:

没有答案