The CallKit code is a sample report without Task, it is running correctly
I used Task for LiveCommunicationKit because the ConversationManager.reportIncomingNewConversation method can only be called with await.
And the success rate is relatively high when the app is not running, but it is highly likely to fail when the app is in the background.
if #available(iOS 17.4, *) {
var update = Conversation.Update(members: [Handle(type: .generic, value: callerName, displayName: callerName)])
update.capabilities = .playingTones
print("Received push")
Task {
print("LCKit Start Answer")
do {
try await LCKitManager.shared.reportNewIncomingConversation(uuid: uuid, update: update)
print("LCKit Answer Success")
completion()
} catch {
print(error)
completion()
}
}
} else {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: callerName)
update.localizedCallerName = callerName
provider.reportNewIncomingCall(with: uuid, update: update) { _ in
completion()
}
}
If the issue is related to Task, it still reports error in the background even after I changed the PushKit delegate method to func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) async, it still reports errors in the background. It even doesn't print received push when the pushRegistry is init with main queue, and it prints received push and LCKit Start Answer when the pushRegistry is init with a custom queue.
If the application is not running, the
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) async {
print("received push")
if type != .voIP { return }
let dic = payload.dictionaryPayload
guard let uuidString = dic["uuid"] as? String,
let uuid = UUID(uuidString: uuidString),
let callerName = dic["callerName"] as? String else {
return
}
if #available(iOS 17.4, *) {
let update = Conversation.Update(members: [Handle(type: .generic, value: callerName, displayName: callerName)], capabilities: .playingTones)
try? await LCKitManager.shared.reportNewIncomingConversation(uuid: uuid, update: update)
}
}