Skip to main content
This page contains iOS SDK code examples for Collaboration extensions. For feature documentation, setup instructions, and extension settings, see Collaboration Extensions.

How to Use Extensions with SDK

1

Enable in Dashboard

Login to CometChat Dashboard, select your app, then go to Chat & Messaging → Features and enable the extension.
2

Implement SDK methods

Use the code examples below to initiate collaboration sessions and extract URLs from messages.
3

Build your UI

Create UI components to display the collaboration interface (e.g., embed the whiteboard/document URL in a WKWebView).

Collaborative Document

Co-edit documents in real-time with other users.

Initiating the Session

CometChat.callExtension(slug: "document", type: .post, endPoint: "v1/create",
body: ["receiverType":"user/group", "receiver":"uid/guid"], onSuccess: { (response) in
        // Success response
      }) { (error) in
        // Some error occured
      }

Extracting the URL from Received Message

if let metaData = message.metaData, 
   let injected = metaData["@injected"] as? [String: Any], 
   let extensions = injected["extensions"] as? [String: Any], 
   let documentExtension = extensions["document"] as? [String: Any],
   let documentUrl = documentExtension["document_url"] as? String {
    print("Document URL:", documentUrl)
}

Collaborative Whiteboard

Draw and brainstorm together on a shared whiteboard.

Initiating the Session

CometChat.callExtension(slug: "whiteboard", type: .post, endPoint: "v1/create", body: ["receiverType":"user/group", "receiver":"uid/guid"], onSuccess: { (response) in
        // Success response
      }) { (error) in
        // Some error occured
      }

Extracting the URL from Received Message

if let metaData = message.metaData, 
   let injected = metaData["@injected"] as? [String: Any], 
   let extensions = injected["extensions"] as? [String: Any], 
   let whiteboardObject = extensions["whiteboard"] as? [String: Any],
   let boardUrl = whiteboardObject["board_url"] as? String {
    print("Whiteboard URL:", boardUrl)
}

Append Username to the Whiteboard URL

CometChat.getLoggedInUser { user in
    guard let user = user else { return }
    // Replace spaces with underscore
    let username = user.name?.replacingOccurrences(of: " ", with: "_") ?? ""
    // Append the username to the board_url
    let finalUrl = "\(boardUrl)&username=\(username)"
    print("Final Whiteboard URL:", finalUrl)
} onError: { error in
    print("Error getting user:", error?.errorDescription ?? "")
}