Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VOIP Notification Not Working to End Call in iOS 18.2 with Flutter CallKit Incoming #618

Open
rohit-saini3103 opened this issue Dec 23, 2024 · 7 comments

Comments

@rohit-saini3103
Copy link

I am facing an issue with handling VOIP notifications in my Flutter application when using the flutter_callkit_incoming plugin on iOS 18.2. Specifically, when I try to send a VOIP notification to end a call, the behavior is inconsistent, and the call does not get terminated as expected.

Steps to Reproduce:
1. Set up flutter_callkit_incoming with VOIP push notifications for incoming calls.
2. Send a VOIP push notification with the intent to end the call.
3. On iOS 18.2, the app doesn’t respond as expected, and the call remains active.

Expected Behavior:

When sending a VOIP notification to end a call, the app should properly respond by ending the call and dismissing the CallKit UI.

Actual Behavior:

The VOIP notification is received, but the app get crashed. and display a pop up of that crash.

Environment:
• iOS version: 18.2
• Flutter version: 3.24.4
• flutter_callkit_incoming plugin version: 2.0.4+2
• Device: iPhone 11

@hanishk
Copy link

hanishk commented Jan 10, 2025

@rohit-saini3103 Did you find any solution? In my case the call is ended but later its shows crash popup

@owl-madness
Copy link

Did you received incoming call notification while the app is in terminated state in iOS??

@hanishk
Copy link

hanishk commented Jan 14, 2025

Yes. Make sure you the silent PN is coming from APN with voip config from backend or tool mentioned in package. Then in xcode you have to implement Pushkit acc to Pushkit.md doc

@owl-madness
Copy link

can you explain how to send a silent push notification? is that same as VoIP notification?
nb: I am using CLoudKit - push notification (ios console) to send VoIP notification

@hanishk
Copy link

hanishk commented Jan 14, 2025

something like this:
{
"aps": {
"content-available": 1
},
"id": "12345",
"callFrom": "John Doe",
}
in body same voip pn,
add com.example.yourapp.voip
use auth .p8 file
check env of sandbox and production depending on build. if its archive its production.

@owl-madness
Copy link

owl-madness commented Jan 14, 2025

See, I implemented VoIP in my project. Using CXProvider I'm showing incoming call notification. when the app is opened the call is shown correctly, but when the app is terminated VoIP is received but it's just waking the app. also the data received through VoIP is not printing anywhere. So I stored the VoIP data to UserDefaults when VoIP notification received and show call incoming using data from UserDefaults when app is waking up. Now the problem is when the app is terminated the data showing in Incoming call is the data stored when the app is open.
and also the incoming call is shown only for a few seconds like 3-5 sec !!
How to solve this??

@hanishk
Copy link

hanishk commented Jan 14, 2025

Here's my code looks like in AppDelegate.swift make sure these methods are there as mentioned in Pushkit.md in this package

// Imports
import CallKit
import AVFAudio
import PushKit
import Flutter
import flutter_callkit_incoming

// main
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate, CallkitIncomingAppDelegate,

// 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("")
}

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    guard type == .voIP else { return }

// print("Incoming push payload: (payload.dictionaryPayload)")

    // Extract payload details
    let id = payload.dictionaryPayload["id"] as? String ?? UUID().uuidString
    let callFrom = payload.dictionaryPayload["callFrom"] as? String ?? "Unknown Caller"
    
    // Prepare CallKit Data
    let callData = flutter_callkit_incoming.Data(
        id: id,
        nameCaller: callFrom,
        handle: subscriberName,
        type: 0 // Audio Call
        
    )
    
    callData.extra = [
        "extra": extraValues
    ]

// in Flutter side u have to implement event listener inside their you can get these extra params and perform operations in flutter side

    // Show the incoming call on the main thread
    SwiftFlutterCallkitIncomingPlugin.sharedInstance?.showCallkitIncoming(callData, fromPushKit: true)
          
          //Make sure call completion()
          DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
              completion()
          }
}

rest is same as onAccept, and other required functions.

and the pn should be APN and .voip type if all are configured properly it will ring and if time is 3 or 4 sec check if its failed due to iOS thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants