minor fix for CallKit PN

This commit is contained in:
ryanzhao 2021-11-08 17:02:47 +11:00
parent 888df37581
commit 86aced218a
2 changed files with 12 additions and 8 deletions

View File

@ -236,15 +236,17 @@ public enum PushRegistrationError: Error {
}
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
SNLog("[Calls] Receive new voip notification.")
owsAssertDebug(CurrentAppContext().isMainApp)
owsAssertDebug(type == .voIP)
let payload = payload.dictionaryPayload
if let uuid = payload["uuid"] as? String, let caller = payload["caller"] as? String {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.createNewIncomingCall(caller: caller, uuid: uuid)
appDelegate.startPollerIfNeeded()
appDelegate.startClosedGroupPoller()
appDelegate.startOpenGroupPollersIfNeeded()
let call = SessionCall(for: caller, uuid: uuid, mode: .answer)
call.reportIncomingCallIfNeeded { error in
if let error = error {
SNLog("[Calls] Failed to report incoming call to CallKit due to error: \(error)")
}
}
}
}
}

View File

@ -220,17 +220,19 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
if #available(iOSApplicationExtension 14.5, *) {
if let uuid = callMessage.uuid, let caller = callMessage.sender {
let payload = ["uuid": uuid, "caller": caller]
return CXProvider.reportNewIncomingVoIPPushPayload(payload) { error in
CXProvider.reportNewIncomingVoIPPushPayload(payload) { error in
if let error = error {
self.contentHandler!(content)
owsFailDebug("Failed to notify main app of call message: \(error)")
} else {
self.completeSilenty()
Logger.info("Successfully notified main app of call message.")
}
self.completeSilenty()
}
}
} else {
self.contentHandler!(content)
}
self.contentHandler!(content)
}
private func handleSuccess(for content: UNMutableNotificationContent) {