How to set up Voip based push notification

how to receive call in background state using callKit. and how to set up Voip certificates in portal

Hello @platinumcode,

Since, we are using firebase for the push notifications, there is not support for push-kit from firebase which is required for the call-kit.
For now, you can receive the push notification for incoming call.
We are tracking your request. https://feedback.cometchat.com/cometchat-pro-feature-requests/p/callkit-support-for-voice-video-calling-for-ios

Noted.
Even it is firebase, am receiving notification as “Incoming call” when app in background. when I open it app not showing incoming call screen.

@platinumcode,

You need to manage it after tapping on push notification.

Once, push notification is received you can convert the payload into a call object. https://prodocs.cometchat.com/docs/ios-extensions-push-notification#converting-push-notification-payload-to-message-object.
Using call object you can perform start call.

@pushpsen.airekar. Plz give me sample code for converting payload into call object and start call.

Hello @platinumcode,

Here is the code for converting payload to Call Object.

  func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        
        if let userInfo = (notification.request.content.userInfo as? [String : Any]){
            let messageObject = userInfo["message"]
            if let someString = messageObject as? String {
                if let dict = someString.stringTodictionary(){
                    print("Call Object: \(CometChat.processMessage(dict))")
                    if let currentcall = CometChat.processMessage(dict).0 as? Call {
                        if currentcall.callStatus == .initiated {
                            DispatchQueue.main.async {
                                // Perform action
                                }
                            }
                        }
                    }
                }
            }
        }
    } 

extension String {
    
    func stringTodictionary() -> [String:Any]? {
        
        var dictonary:[String:Any]?
        
        if let data = self.data(using: .utf8) {
            
            do {
                dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]
                
                if let myDictionary = dictonary
                {
                    return myDictionary;
                }
            } catch let error as NSError {
                print(error)
            }
            
        }
        return dictonary;
    }
}
1 Like

Thank you…

May I know how to enable and disable speaker?

hello @platinumcode,

During call there is an option by default given by us to switch to speaker/ earpiece mode.
If you want to disable the ringing sounds then you can use CometChatSoundManager() Class and provide ‘false’ value to disable specific sound if it is playing.

Thank you. I will try this

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.