수고하십니다.
아직 이 문제가 해결되지 않아서 도움을 요청드립니다.
해당 소스는 아래와 같습니다.
보시고 잘못된 부분이 있으면 알려주시면 고맙겠습니다.
//
// MainVC+PKPush.swift
// CarrotCall
//
// Created by swlee on 2020/10/11.
//
import Foundation
import CallKit
import PushKit
import RemoteMonster
extension MainVC: CXProviderDelegate, PKPushRegistryDelegate {
func providerDidReset(_ provider: CXProvider) {
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
doPrint("통화 응답 CXAnswerCallAction channelId = [\(channelId)]");
action.fulfill()
self.doRemonInit()
remonCall.connect(channelId)
}
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
doPrint("통화 시작 CXStartCallAction");
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
doPrint("sender uuid", action.callUUID.uuidString)
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
doPrint("통화 종료 CXEndCallAction");
action.fulfill()
remonCall.closeRemon()
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
doPrint("pushRegistry didInvalidatePushTokenFor")
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
doPrint("pushRegistry didUpdate")
let token = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
//let d = NSData(data: pushCredentials.token)
//print("token is data", d.description)
doPrint("token is ", token)
LibLocalData.doPushkitTokenSet(sPushkitToken: token)
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
doPrint("pushRegistry didReceiveIncomingPushWith")
doPrint(payload)
let dicPayload:[AnyHashable: Any] = payload.dictionaryPayload
if let target:[String: String] = dicPayload["target"] as? [String: String] {
doPrint(target["deviceId"])
doPrint(target["idKey"])
doPrint(target["channelId"])
doPrint(target["idxSchedule"])
doPrint(target["url"])
let uuid = UUID()
doPrint(uuid.uuidString)
doPrint("-------------------------")
let idKey:String = target["idKey"] ?? ""
if let channelId_:String = target["channelId"] {
channelId = channelId_
update.remoteHandle = CXHandle(type: .generic, value: idKey)
provider.reportNewIncomingCall(with: uuid, update: update, completion: { error in })
}
}
}
func doVoipRegistration() {
let mainQueue = DispatchQueue.main
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
}
func doCxProviderInit() {
if provider != nil {return}
let cxProviderConf:CXProviderConfiguration = CXProviderConfiguration()
cxProviderConf.supportsVideo = false
cxProviderConf.supportedHandleTypes = [.generic]
cxProviderConf.maximumCallGroups = 1
cxProviderConf.maximumCallsPerCallGroup = 5
provider = CXProvider(configuration: cxProviderConf)
provider.setDelegate(self, queue: nil)
}
func doRemonInit() {
doPrint("doRemonInit()...")
remonCall.onInit {
doPrint("********** remonCall.onInit")
DispatchQueue.main.async {
}
}
remonCall.onComplete { () in
doPrint("********** remonCall.onComplete")
DispatchQueue.main.async {
// 녹음 시작
self.doRecordingStart()
}
}
remonCall.onClose { (_) in
doPrint("********** remonCall.onClose")
DispatchQueue.main.async {
self.remonCall.closeRemon()
self.doRecordingFinish(success: true)
}
}
remonCall.onError { (error) in
doPrint("********** remonCall.onError")
doPrint(error.localizedDescription)
DispatchQueue.main.async {
//error.localizedDescription
self.doRecordingFinish(success: true)
}
}
}
}