Code: Select all
func registerForVoIPPushes() {
self.voipRegistry = PKPushRegistry(queue: nil)
self.voipRegistry?.delegate = self
self.voipRegistry?.desiredPushTypes = [.voIP]
}
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
registerForVoIPPushes()
return true
}
Code: Select all
func pushRegistry(_ registry: PKPushRegistry,
didReceiveIncomingPushWith payload: PKPushPayload,
for type: PKPushType) {
guard let payloadInfo = payload.dictionaryPayload["data"] as? [AnyHashable: Any] else {
print("Unidentifiable payload data received")
return
}
print("pushRegistry didReceiveIncomingPushWith \(payloadInfo)")
guard
type == .voIP,
let callId = payloadInfo["callId"] as? String,
let _ = payloadInfo["deviceId"] as? String,
let sender = payloadInfo["senderName"] as? String,
let type = payloadInfo["type"] as? String
else {
print("Unknown PushKit notification received")
return
}
let uuid = GlobalMethods().uuidFromString(callId)
switch type {
case "NewVoipCallStarted":
CallManager.shared.processForIncomingCall(sender: sender, uuid: uuid)
case "CancelVoipCall":
CallManager.shared.cancelIncomingCall(uuid: uuid)
default:
print("Unknown type of voIP notification received")
return
}
}
func processForIncomingCall(sender: String, uuid: UUID) {
let configuration = CXProviderConfiguration()
configuration.supportsVideo = true
configuration.includesCallsInRecents = true
configuration.supportedHandleTypes = [.generic]
configuration.maximumCallsPerCallGroup = 1
configuration.includesCallsInRecents = true
provider = CXProvider(configuration: configuration)
provider?.setDelegate(self, queue: nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: sender)
update.hasVideo = true
provider?.reportNewIncomingCall(with: uuid, update: update) { error in
if let error = error {
print("Error reporting incoming call: \(error.localizedDescription)")
} else {
print("Incoming call successfully reported.")
}
}
}
< /code>
Was ich ausprobiert habe: < /strong>
• Überprüft, ob das VoIP-Push-Zertifikat ordnungsgemäß gültig ist. Jedes Mal, wenn die App startet. immer ankommen und pushregistry aufrufen (_: didreceieComingpushwith: für

auch wenn die App im Hintergrund oder beendet ist. < /p.>