SendBirdCall

@objcMembers
@objc(SBCSendBirdCall)
public class SendBirdCall : NSObject

SendBirdCall

  • The app id of your SendBirdCalls application. Configure the app id using configure(appId:). This is get-only property.

    Important

    If you change the app ID, a previous configured app ID will be removed and all calls will be canceled.
    SendBirdCall.appId    // "Optional(YOUR_APP_ID)"
    

    Since

    1.0.0

    Declaration

    Swift

    public static var appId: String? { get }
  • Initiate SendBirdCall instance when a client app is launched. If another initialization with another APP_ID takes place, all existing data will be deleted and the SendBirdCall instance will be initialized with the new APP_ID.

    SendBirdCall.configure(appId: "YOUR_APP_ID")
    

    Since

    1.0.0

    • Tag: configure(appId)

    Declaration

    Swift

    @discardableResult
    public static func configure(appId: String) -> Bool

    Parameters

    appId

    Your own app ID from your dashboard

    Return Value

    (Discardable)Bool value. If the paramter has an empty string or equal previous app ID, it returns false. If the method configures app ID successfully, it returns true.

  • SendBirdCalls SDK Version

    self.versionLabel.text = "SendBirdCalls v\(SendBirdCall.sdkVersion)"
    
    // "SendBirdCalls v1.0.0"
    

    Since

    1.0.0

    Declaration

    Swift

    public static var sdkVersion: String { get }

Audio I/O

  • Provides a view that allows user to change the system audio route. Returns AVRoutePickerView in iOS 11 or later and MPVolumeView in earlier iOS version.

    let routePickerView = SendBirdCall.routePickerView(frame: frame)
    self.parentView.addSubView(routePickerView)
    
    • Customization
    if #available(iOS 11.0, *) {
       guard let routePickerView = routePickerView as? AVRoutePickerView else { return }
       // Set up AVRoutePickerView
    } else {
       guard let routePickerView = routePickerView as? MPVolumeView else { return }
       // Set up MPVolumeView
    }
    
    
    

    Since

    1.0.0

    • Tag: routePickerView(frame)

    Declaration

    Swift

    public static func routePickerView(frame: CGRect) -> UIView

    Parameters

    frame

    CGRect value that is assigned to view’s frame.

    Return Value

    AVRoutePickerView in iOS 11.0 or later. (MPVolumeView in previous iOS version)

Thread

  • Specifies the queue that you want to use for callbacks and delegate methods

    Since

    1.0.0

    Declaration

    Swift

    public static func executeOn(queue: DispatchQueue)

    Parameters

    queue

    DispatchQueue that will be used when callbacks and delegates are called.

Delegates

  • Registers a device-specific SendBirdCallDelegateevent handler. Responding to device-wide events (e.g. incoming calls) is then managed as shown below:

    SendBirdCall.addDelegate(self, identifier: UNIQUE_HANDLER_ID)
    
    func didStartRinging(_ call: DirectCall) {
        call.delegate = self
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public static func addDelegate(_ delegate: SendBirdCallDelegate, identifier: String)

    Parameters

    delegate

    SendBirdCallDelegate that listens to SendBirdCall events

    identifier

    Identifier for the specific delegate

  • Removes delegate for the given identifier.

    Since

    1.0.0

    Declaration

    Swift

    public static func removeDelegate(identifier: String)

    Parameters

    identifier

    String identifier for the delegate. If SendBirdCall doesn’t have the given identifier, it will be ignored.

  • Removes all delegate for SendBirdCall events.

    Since

    1.0.0

    Declaration

    Swift

    public static func removeAllDelegates()
  • Adds a SendBirdRecordingDelegate to the SDK which is invoked when a recording session is finished successfully.

    SendBirdCall.addRecordingDelegate(self, identifier: UNIQUE_HANDLER_ID)
    
    func didSaveRecording(call: DirectCall, recordingId: String, options: RecordingOptions, outputURL: URL) {
       // Handle successful recording
    }
    
    func didFailToSaveRecording(call: DirectCall, recordingId: String, error: SBCError) {
       // Handle failed recording
    }
    

    Since

    1.3.0

    Declaration

    Swift

    public static func addRecordingDelegate(_ delegate: SendBirdRecordingDelegate, identifier: String)

    Parameters

    delegate

    A RecordingDelegate to add to the SDK.

    identifier

    A unique identifier for the RecordingDelegate.

  • Removes a SendBirdRecordingDelegate that has the specified identifier from the SDK.

    Since

    1.3.0

    Declaration

    Swift

    public static func removeRecordingDelegate(identifier: String)

    Parameters

    identifier

    A unique identifier of a RecordingDelegate to remove from the SDK.

  • Removes all SendBirdRecordingDelegates from the SDK.

    Since

    1.3.0

    Declaration

    Swift

    public static func removeAllRecordingDelegates()

Call

  • Returns call for call ID.

    Since

    1.0.0

    Declaration

    Swift

    @objc(callForCallId:)
    public static func getCall(forCallId callId: String) -> DirectCall?

    Parameters

    callId

    Call ID.

    Return Value

    DirectCall object with corresponding call ID. It can be nil.

  • Returns call for a given UUID.

    Declaration

    Swift

    @objc(callForUUID:)
    public static func getCall(forUUID callUUID: UUID) -> DirectCall?

    Parameters

    callUUID

    Call UUID.

    Return Value

    DirectCall object with corresponding call ID. It can be nil.

    • callUUID: Call UUID.

    Since

    1.0.0
  • Returns number of ongoing calls.

    Since

    1.2.0

    Declaration

    Swift

    public static func getOngoingCallCount() -> Int
  • Returns all ongoing calls, including the active call and all calls on hold.

    Since

    1.8.0

    Declaration

    Swift

    public static func getOngoingCalls() -> [DirectCall]

Authenticate

  • Returns the currently authenticated user.

    Since

    1.0.0

    Declaration

    Swift

    public static var currentUser: User? { get }

    Return Value

    User that is currently authenticated. Returns nil if no user exists.

  • Authenticates user with user ID and access token that you generated at SendBird Dashboard. In order to make and receive calls, authenticate the user with SendBird server with the the SendBirdCall.authenticate()method.

    let params = AuthenticateParams(userId: userId, accessToken: accessToken)
    
    SendBirdCall.authenticate(with: params) { user, error in
        guard let user = user, error == nil else {
            return
        }
    }
    

    Since

    1.0.0
    • Tag: authenticate(with,completionHandler)

    Declaration

    Swift

    @objc(authenticateWithParams:completionHandler:)
    public static func authenticate(with params: AuthenticateParams, completionHandler: @escaping AuthenticateHandler)

    Parameters

    params

    AuthenticateParams that contains User Id, Access Token, Push Token, and Unique

    completionHandler

    The handler to call when the authenication is complete.

  • Deauthenticates user. To stop receiving calls after deauthentication, you should unregister according push tokens by calling unregisterVoIPPush and unregisterRemotePush before deauthenticating.

    SendBirdCall.unregisterVoIPPush(token: myVoIPPushToken) { error in // Unregister push tokens to stop receiving push notifications on deauhtenticated devices. Unregistering push tokens must be done before deauthenticating.
       // Handle unregister push token
    
       SendBirdCall.deauthenticate { error in
           guard error == nil else {
               // handle error
               return
           }
       )
    }
    

    Since

    1.1.0

    Declaration

    Swift

    public static func deauthenticate(completionHandler: ErrorHandler?)

    Parameters

    completionHandler

    Error Handler to be called after deauthenticate process is finished

Dial

  • Makes a call to user(callee) directly. (1:1 Call). Use the CallOptions object to choose initial call configuration (e.g. muted/unmuted)

     let params = DialParams(calleeId: CALLEE_ID, callOptions: CallOptions())
    
     let directCall = SendBirdCall.dial(with: params) { directCall, error in
         //
     }
    
     directCall.delegate = self
    

    Since

    1.0.0
    • Tag: dial(with,completionHandler)

    Declaration

    Swift

    @discardableResult
    @objc(dialWithParams:completionHandler:)
    public static func dial(with params: DialParams, completionHandler: @escaping DirectCallHandler) -> DirectCall?

    Parameters

    params

    DialParams that contains calleeId, videoCall flag, CallOptions, and customItems.

    completionHandler

    Callback completionHandler to be called after dialing.

    Return Value

    (Discardable) DirectCall object. If the method failed to make a call, it would return nil.

Ringing Timeout

  • Sets timeout value for the timeout period before unanswered ringing or dialing calls expires and ends. Its default value is 60 seconds.

    Important

    If you assign invalid value(0 or negative value), it will be ignored

    SendBirdCall.setRingingTimeout(30)
    

    Since

    1.0.5

    Declaration

    Swift

    public static func setRingingTimeout(_ timeout: Int)

    Parameters

    timeout

    Timeout value in seconds.

  • Sets timeout value for the timeout period before the call is connected. Default value is 60 seconds.

    Important

    If you assign invalid value(0 or negative value), it will be ignored.

    SendBirdCall.setCallConnectingTimeout(30)
    

    Since

    1.2.0

    Declaration

    Swift

    public static func setCallConnectingTimeout(_ timeout: Int)

    Parameters

    timeout

    Timeout value in seconds.

Push

  • Handles incoming VoIP push with SendBirdCalls payload. Incoming calls are received either via the application’s persistent internal server connection, or (if the application is in the background) via PushKit. PushKit messages received by the SendBirdCall instance MUST be delivered to the SDK.

    class MyClass: PKPushRegistryDelegate {
        func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
            SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) { uuid in
    
                // IMPORTANT: You MUST report incoming call to CallKit when you receive a pushkit push.
                let provider = CXProvider(configuration: CXProviderConfiguration)
                let update = CXCallUpdate()
                update.remoteHandle = CXHandle(type: .generic, value: HANDLE_VALUE)
                provider.reportNewIncomingCall(with: uuid, update: update) { error in
                    completion()
                })
            }
        }
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public static func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completionHandler: PushRegistryHandler?)

    Parameters

    registry

    PKPushRegistry object same as PKPushRegistryDelegate registry.

    payload

    PKPushPayload in incoming VoIP push notification.

    type

    PKPushType of push(VoIP)

    completionHandler

    This closure is invoked with UUID from the payload.

  • To receive native-like calls while an app is in the background or closed, a device registration token must be registered to the server. Register a device push token during authentication by either providing it as a parameter in the SendBirdCall.authenticate() method, or after authentication has completed using the SendBirdCall.registerVoIPPushToken() method.

    // PKPushRegistryDelegate
    class AppDelegate: PKPushRegistryDelegate {
        func voipRegistration() {
            self.voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
            self.voipRegistry?.delegate = self
            self.voipRegistry?.desiredPushTypes = [.voIP]
        }
    
        ...
        func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
            SendBirdCall.registerVoIPPush(token: pushCredentials.token) { (error) in
                guard let error = error else {
                    return
                }
                // The Push Token has been registered successfully
            }
        }
        ...
    }
    

    Since

    1.0.0
    • Tag: registerVoIPPush(token,unique,completionHandler)

    Declaration

    Swift

    public static func registerVoIPPush(token: Data?, unique: Bool = false, completionHandler: ErrorHandler?)

    Parameters

    token

    Data object from pushCredential.token. Refer to PKPushRegistryDelegate

    unique

    If it is false, you can register more token for multi devices. It has false as a default value.

  • Unregisters a VoIP push token of specific device. You will not receive VoIP push notification for a call anymore. If you don’t want to receive a call in all of the devices of the users, call unregisterAllVoIPPushTokens(completionHandler:).

    func removeVoIPPushToken() {
        SendBirdCall.unregisterVoIPPush(token: myVoIPPushToken) { error in
        guard error == nil else { return }
        // Unregistered successfully
    }
    

    Since

    1.0.0
    • Tag: unregisterVoIPPush(token,completionHandler)

    Declaration

    Swift

    public static func unregisterVoIPPush(token: Data?, completionHandler: ErrorHandler?)

    Parameters

    token

    Optional Data for the push token that you want to unregister

    completionHandler

    ErrorHandler that returns callback with error.

  • Unregister all VoIP push token registered to the current user(multi device). You will not receive a call in all of the devices of the users.

    func removeAllOfVoIPPushTokens() {
        func unregisterAllVoIPPushTokens(completionHandler: ErrorHandler?) {
            guard error == nil else { return }
            // Unregistered all push tokens successfully
        }
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public static func unregisterAllVoIPPushTokens(completionHandler: ErrorHandler?)

    Parameters

    completionHandler

    ErrorHandler that returns callback with error

  • To receive remote notifications when the app is in the background or closed, you must deliver the received remote notification to SendBirdCalls SDK.

    Note

    SendBirdCall will only process SendBird’s notifications. If the userInfo does not contain SendBirdCall’s payload, method will be returned without processing the payload so that you can control the push notifications at your will.

    class AppDelegate {
        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
            SendBirdCall.application(application, didReceiveRemoteNotification: userInfo)
        }
    }
    

    Since

    1.0.3

    Declaration

    Swift

    public static func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])

    Parameters

    application

    Your singleton app object.

    userInfo

    A dictionary that contains information about incoming SendBird Calls.

  • To receive remote notifications while an app is in the background or closed, a device registration token must be registered to the server. Register a remote push token during by using the SendBirdCall.registerRemotePushToken() method.

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
       SendBirdCall.registerRemotePush(token: deviceToken) { error in
           //
       }
    }
    

    Note

    You must register the device to receive remote notifications via Apple Push Notification service for application(_:didRegisterForRemoteNotificationsWithDeviceToken:) to be called. Refer to UIApplication.registerForRemoteNotifications().

    Since

    1.0.3

    • Tag: registerRemotePush(token:unique:completionHandler:)

    Declaration

    Swift

    public static func registerRemotePush(token: Data?, unique: Bool = false, completionHandler: ErrorHandler?)

    Parameters

    token

    Unique Token that identifies the device to APNs. Provide the token to register to SendBird.

    unique

    If it is false, you can register more token for multi devices. It has false as a default value.

  • Unregisters a remote push token of specific device. You will not receive remote push notification on the device anymore. If you don’t want to receive remote notifications in all of the devices of the users, call unregisterAllRemotePushTokens(completionHandler:).

    • token: Optional Data for the push token that you want to unregister
    • completionHandler: ErrorHandler that returns callback with error.
    func removeRemotePushToken() {
       SendBirdCall.unregisterRemotePush(token: myRemotePushToken) { error in
           guard error == nil else { return }
           // Unregistered successfully
       }
    }
    

    Since

    1.0.3

    • Tag: unregisterRemotePush(token,completionHandler)

    Declaration

    Swift

    public static func unregisterRemotePush(token: Data?, completionHandler: ErrorHandler?)
  • Unregister all remote push token registered to the current user(multi device). You will not receive remote notifications in all of the devices of the users.

    func removeAllOfRemotePushTokens() {
        func unregisterAllRemotePushTokens(completionHandler: ErrorHandler?) {
            guard error == nil else { return }
            // Unregistered all remote push tokens successfully
        }
    }
    

    Since

    1.0.3

    Declaration

    Swift

    public static func unregisterAllRemotePushTokens(completionHandler: ErrorHandler?)

    Parameters

    completionHandler

    ErrorHandler that returns callback with error

Query

  • Creates a Direct Call Log List Query from given params.

    Since

    1.0.0

    Declaration

    Swift

    @objc(createDirectCallLogListQueryWithParams:)
    public static func createDirectCallLogListQuery(with params: DirectCallLogListQuery.Params) -> DirectCallLogListQuery?

    Parameters

    params

    DirectCallLogListQuery Params with options for creating query.

    Return Value

    DirectCallLogListQuery: Returns optional query object. Returns nil if current user does not exit.

  • Creates a query for room list with specified parameters.

    Since

    1.7.0

    Declaration

    Swift

    public static func createRoomListQuery(with params: RoomListQuery.Params) -> RoomListQuery?

    Parameters

    params

    RoomListQuery Params with options for creating query.

Custom Items

  • Updates custom items for a given call Id.

    Since

    1.0.0

    Declaration

    Swift

    public static func updateCustomItems(callId: String, customItems: [String : String], completionHandler: @escaping CustomItemsHandler)

    Parameters

    callId

    Call ID.

    customItems

    Custom items of [String: String] to be updated or inserted.

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

  • Deletes custom items for a given call Id.

    Since

    1.0.0

    Declaration

    Swift

    public static func deleteCustomItems(callId: String, customItemKeys: [String], completionHandler: @escaping CustomItemsHandler)

    Parameters

    callId

    Call ID.

    customItemKeys

    Keys of custom items that you want to delete.

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

  • Deletes all custom items for a given call Id.

    Since

    1.0.0

    Declaration

    Swift

    public static func deleteAllCustomItems(callId: String, completionHandler: @escaping CustomItemsHandler)

    Parameters

    callId

    Call ID.

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

  • Called when the audio session is activated outside of the app by iOS.

    class AppDelegate: CXProviderDelegate {
        func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
            SendBirdCall.audioSessionDidActivate(audioSession)
        }
    }
    
    // MARK: - Audio Session
    
    

    Since

    1.0.2

    Declaration

    Swift

    public static func audioSessionDidActivate(_ audioSession: AVAudioSession)
  • Called when the audio session is deactivated outside of the app by iOS.

    class AppDelegate: CXProviderDelegate {
        func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
            SendBirdCall.audioSessionDidDeactivate(audioSession)
        }
    }
    

    Since

    1.0.2

    Declaration

    Swift

    public static func audioSessionDidDeactivate(_ audioSession: AVAudioSession)
  • Adds sound used in DirectCall such as ringtone and some sound effects with its file name and bundle.

    SendBirdCall.addDirectCallSound("dialing.mp3", forType: .dialing)
    

    Since

    1.3.0

    Declaration

    Swift

    public static func addDirectCallSound(_ name: String, bundle: Bundle = .main, forType type: SoundType)

    Parameters

    name

    The name of your audio file. Please explicit its extension: “dialing.mp3”

    bundle

    The bundle object. The default is main bundle.

    type

    The type of sound.

  • Enables / disables dial sound used in DirectCall even when the device is in silent mode. Call this method right after addDirectCallSound(_:forType:).

    SendBirdCall.addDirectCallSound("dialing.mp3", forType: .dialing)
    SendBirdCall.setDirectCallDialingSoundOnWhenSilentMode(isEnabled: true) // Will play dial direct call sounds in silent mode
    

    Since

    1.5.0

    Declaration

    Swift

    @objc(setDirectCallDialingSoundOnWhenSilentMode:)
    public static func setDirectCallDialingSoundOnWhenSilentMode(isEnabled: Bool)

    Parameters

    isEnabled

    If it is true, dial sound used in DirectCall will be played in silent mode.

  • Adds sound used in DirectCall such as ringtone and some sound effects with URL. If you use bundle to play sound, addDirectCallSound(_:bundle:forType:) is recommended.

    SendBirdCall.addDirectCallSound("dialing.mp3", forType: .dialing)
    

    Since

    1.3.0

    Declaration

    Swift

    public static func addDirectCallSound(_ url: URL, forType type: SoundType)

    Parameters

    url

    The URL of your audio file.

    type

    The key respresenting the type of sound.

  • Removes sound used in DirectCall with SoundType value.

    SendBirdCall.removeDirectCallSound(forType: .dialing)
    

    Since

    1.3.0

    Declaration

    Swift

    public static func removeDirectCallSound(forType type: SoundType)

    Parameters

    type

    The type of sound you want to remove.

  • Creates a room for group calls.

    SendBirdCall.createRoom { room, error in
       ...
       // Set up delegate to receive events
    }
    

    Since

    1.6.0

    • Tag: createRoom(with:completionHandler:)

    Declaration

    Swift

    @objc(createRoomWithParams:completionHandler:)
    public static func createRoom(with params: RoomParams, completionHandler: @escaping RoomHandler)

    Parameters

    completionHandler

    A callback function that receives information about a room or an error from Sendbird server.

  • Gets a locally-cached room instance by room ID.

    Since

    1.6.0

    Declaration

    Swift

    @objc(cachedRoomByRoomId:)
    public static func getCachedRoom(by roomId: String) -> Room?

    Parameters

    roomId

    room ID.

    Return Value

    Room object with the corresponding roomId

  • Fetches a room instance from Sendbird server.

    Since

    1.6.0

    Declaration

    Swift

    @objc(fetchRoomByRoomId:completionHandler:)
    public static func fetchRoom(by roomId: String, completionHandler: @escaping RoomHandler)

    Parameters

    roomId

    room ID.

    completionHandler

    Callback to be called after get Room object corresponding the ID or an error