Recently, I attempted to use LiveCommunicationKit to replace CallKit. The goal was to explore better features or integration.
However, a major problem emerged. When the app is in the background or killed, it shows no notifications. This seriously impairs the app's communication functionality as notifications are vital for users to notice incoming calls.
And it is working well when the app is in the foreground.
When the app is in the background, when the push message received. the app get crashed with the following information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push.'
Also, when I use CallKit instead of LiveCommunicationKit, the app works well in all cases.
The code is here:
LCK wrapper:
class LCKWrapper : NSObject, ConversationManagerDelegate {
var mgr: ConversationManager
var lckDelegate: LCKDelegate
var currentCallId: UUID
@objc init(handler: LCKDelegate, appName: String, appIcon: UIImage) {
self.lckDelegate = handler
var iconData: Data?
iconData = appIcon.pngData();
var cfg: ConversationManager.Configuration
cfg = ConversationManager.Configuration(ringtoneName: "ringtone.m4a",
iconTemplateImageData: iconData,
maximumConversationGroups: 1,
maximumConversationsPerConversationGroup: 1,
includesConversationInRecents: false,
supportsVideo: false,
supportedHandleTypes: Set([Handle.Kind.phoneNumber]))
self.mgr = ConversationManager(configuration: cfg)
self.currentCallId = UUID()
super.init()
self.mgr.delegate = self
}
func reportIncomingCall(_ payload: [AnyHashable : Any], callerName: String) async {
do {
print("Prepare to report new incoming conversation")
self.currentCallId = UUID()
var update = Conversation.Update()
let removeNumber = Handle(type: .generic, value: callerName, displayName: callerName)
update.activeRemoteMembers = Set([removeNumber])
update.localMember = Handle(type: .generic, value: "", displayName: callerName);
update.capabilities = [ .playingTones ];
try await self.mgr.reportNewIncomingConversation(uuid: self.currentCallId, update: update)
print("report new incoming conversation Done")
} catch {
print("unknown error: \(error)")
}
}
}
And the PushKit wrapper:
@available(iOS 17.4, *)
@objc class PushKitWrapper : NSObject, PKPushRegistryDelegate {
var pushKitHandler: PuskKitDelegate
var lckHandler: LCKWrapper
@objc init(handler: PuskKitDelegate, lckWrapper: LCKWrapper) {
self.pushKitHandler = handler
self.lckHandler = lckWrapper
super.init()
let mainQueue = DispatchQueue.main
// Create a push registry object on the main queue
let voipRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [.voIP]
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) async {
if (type != .voIP) {
return;
}
await self.lckHandler.reportIncomingCall(payload.dictionaryPayload, callerName: "Tester")
}
}