0

I am sending a VoIP notification to my app to show the call screen. I am using flutter_callkit_incoming to handle these pushes. However, recently I have been getting crashes with the following text from Xcode, saying this is the line causing the crash

PushKit 0x229d90744 -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes] + 168 (PKPushRegistry.m:349)

My AppDelegate.swift

    // Handle updated push credentials
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    print(credentials.token)
    let deviceToken = credentials.token.map { String(format: "%02x", $0) }.joined()
    print(deviceToken)
    //Save deviceToken to your server
    SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)
}

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
    print("didInvalidatePushTokenFor")
    SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP("")
}

    // Handle incoming pushes
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    print("didReceiveIncomingPushWith")
    guard type == .voIP else { return }
    
    let id = payload.dictionaryPayload["id"] as? String ?? ""
    let nameCaller = payload.dictionaryPayload["nameCaller"] as? String ?? ""
    let handle = payload.dictionaryPayload["handle"] as? String ?? ""
    let isVideo = payload.dictionaryPayload["isVideo"] as? Bool ?? false
    let notType = payload.dictionaryPayload["notType"] as? String ?? ""
    
    let data = flutter_callkit_incoming.Data(id: id, nameCaller: nameCaller, handle: handle, type: isVideo ? 1 : 0)
    //set more data
    data.extra = ["user": "abc@123", "platform": "ios"]
    //data.iconName = ...
    //data.....
    if (notType == "cancel") {
        print("didReceiveIncomingPushWith - Ending call")
        SwiftFlutterCallkitIncomingPlugin.sharedInstance?.endAllCalls();    
    } else {
        SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(data, fromPushKit: true)
    }
}

How I am sending the VoIP notificaiton

var note = new apn.Notification();

        note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
        note.alert = `\uD83D\uDCE7 \u2709 ${userTitle} call`;
        note.payload = { 'nameCaller': userTitle, 'isVideo': isVideo, 'id': uuid ?? uuidv4(), 'notType': notType };
        note.pushType = "voip"
        const bundleId = isProd ? process.env.BUNDLE_ID_PROD : process.env.BUNDLE_ID_DEV
        note.topic = `${bundleId}.voip`;
        console.log('APN: 5')

        apnProvider.send(note, deviceToken).then((result) => {
            // see documentation for an explanation of result
            if (result.failed.length > 0) {
                console.log('APN Failed: ' + result.failed[0].response.reason || "Unknown")
            } else {
                console.log('APN Succeeded.')
            }
        });
Abdelrahman
  • 623
  • 7
  • 13

0 Answers0