Guide to implementing voice and video calls with ringing functionality using the CometChat iOS SDK including call initiation, acceptance, and rejection.
This section explains how to implement a complete calling workflow with ringing functionality, including incoming/outgoing call UI, call acceptance, rejection, and cancellation. Previously known as Default Calling.
After the call is accepted, you need to start the call session. See the Call Session guide for details on starting and managing the actual call.
Call Flow:
Caller initiates a call using initiateCall()
Receiver gets notified via onIncomingCallReceived() callback
Receiver can either:
Accept the call using acceptCall()
Reject the call using rejectCall() with status .rejected
Caller can cancel the call using rejectCall() with status .cancelled
Once accepted, both participants call startSession() to join the call
Invoked when an incoming call is received. Display incoming call UI here.
onOutgoingCallAccepted(acceptedCall: Call)
Invoked on the caller’s device when the receiver accepts. Start the call session here.
onOutgoingCallRejected(rejectedCall: Call)
Invoked on the caller’s device when the receiver rejects. Dismiss outgoing call UI.
onIncomingCallCanceled(canceledCall: Call)
Invoked on the receiver’s device when the caller cancels. Dismiss incoming call UI.
onCallEndedMessageReceived(endedCall: Call)
Invoked when a call ends. Update call history here.
Sample Payloads - Call Listener Events
onIncomingCallReceived
onOutgoingCallAccepted
onOutgoingCallRejected
onIncomingCallCanceled
onCallEndedMessageReceived
Method:onIncomingCallReceived(incomingCall: Call?, error: CometChatException?)Triggered on: Receiver’s device when someone initiates a call to themIncoming Call Object Properties:
Property
Type
Description
sessionID
String?
Unique call session identifier
callType
CallType
.audio or .video
callStatus
CallStatus
.initiated
callInitiator
User?
User object of the caller
callReceiver
AppEntity?
User or Group object receiving the call
receiverType
ReceiverType
.user or .group
initiatedAt
Double
Timestamp when call was initiated
Method:onOutgoingCallAccepted(acceptedCall: Call?, error: CometChatException?)Triggered on: Caller’s device when the receiver accepts the callAccepted Call Object Properties:
Property
Type
Description
sessionID
String?
Session ID to use for startSession
callStatus
CallStatus
.ongoing
callType
CallType
.audio or .video
callInitiator
User?
User object of the caller
callReceiver
AppEntity?
User or Group that accepted
joinedAt
Double
Timestamp when call was accepted
Method:onOutgoingCallRejected(rejectedCall: Call?, error: CometChatException?)Triggered on: Caller’s device when the receiver rejects the callRejected Call Object Properties:
Property
Type
Description
sessionID
String?
Session ID of rejected call
callStatus
CallStatus
.rejected or .busy
callType
CallType
.audio or .video
callInitiator
User?
User object of the caller
callReceiver
AppEntity?
User or Group that rejected
Method:onIncomingCallCanceled(canceledCall: Call?, error: CometChatException?)Triggered on: Receiver’s device when the caller cancels before they answerCancelled Call Object Properties:
Property
Type
Description
sessionID
String?
Session ID of cancelled call
callStatus
CallStatus
.cancelled
callType
CallType
.audio or .video
callInitiator
User?
User who cancelled the call
callReceiver
AppEntity?
User or Group that was being called
Method:onCallEndedMessageReceived(endedCall: Call?, error: CometChatException?)Triggered on: Both caller and receiver when the call endsEnded Call Object Properties:
Once the call is accepted, both participants need to start the call session.Caller flow: In the onOutgoingCallAccepted() callback, generate a token and start the session.Receiver flow: In the acceptCall() success callback, generate a token and start the session.
Swift
Report incorrect code
Copy
Ask AI
let sessionId = call?.sessionID ?? ""let authToken = CometChat.getUserAuthToken() ?? ""// Step 1: Generate call tokenCometChatCalls.generateToken(authToken: authToken as NSString, sessionID: sessionId) { token in // Step 2: Configure call settings let callSettings = CometChatCalls.callSettingsBuilder .setDefaultLayout(true) .setIsAudioOnly(false) .setDelegate(self) .build() // Step 3: Start the call session CometChatCalls.startSession(callToken: token, callSetting: callSettings, view: self.callView) { success in print("Call session started successfully") } onError: { error in print("Start session failed: \(String(describing: error?.errorDescription))") }} onError: { error in print("Token generation failed: \(String(describing: error?.errorDescription))")}
For more details on call settings and customization, see the Call Session guide.
To end an active call in the ringing flow, the process differs based on who ends the call.User who ends the call:When the user presses the end call button, the onCallEndButtonPressed() callback is triggered. Inside this callback, call CometChat.endCall(). On success, call CometChat.clearActiveCall() and CometChatCalls.endSession().
Swift
Report incorrect code
Copy
Ask AI
func onCallEndButtonPressed() { CometChat.endCall(sessionID: sessionId) { call in CometChat.clearActiveCall() CometChatCalls.endSession() // Close the calling screen } onError: { error in print("End call failed: \(String(describing: error?.errorDescription))") }}