Skip to main content
Enable the current group owner to delegate ownership to another member using CometChat’s UIKit for iOS.

Overview

The Transfer Group Ownership feature provides a modal interface where the group owner can:
  • See a list of current group members (excluding themselves)
  • Select exactly one member to become the new owner
  • Trigger the ownership transfer API call
  • Automatically exit the group after successful transfer

Prerequisites

Before implementing ownership transfer, ensure you have:
  • Completed Getting Started setup
  • CometChat UIKit v5+ installed via CocoaPods or Swift Package Manager
  • CometChatSDK and CometChatUIKitSwift integrated
  • User logged in with CometChatUIKit.login()
  • UINavigationController or modal presentation flow set up
  • Group context (GUID) available when invoking the transfer screen

Components

ComponentDescription
TransferOwnershipSubclass of CometChatGroupMembers enabling single selection mode
viewModel.groupMembersData source array of GroupMember objects
onSelectedItemProceedClosure invoked when user confirms selection
CometChat.transferGroupOwnershipAPI call to delegate group ownership
spinnerViewUIActivityIndicatorView showing loading state
leaveGroupCallbackCallback to perform group exit after transfer

Integration Steps

Step 1: Present Transfer Ownership Screen

Show the ownership transfer UI modally:
File reference: GroupDetailsViewController.swift

Step 2: Configure Single Selection Mode

Restrict selection to one member and capture selection:
File reference: TransferOwnership.swift

Step 3: Load and Filter Member List

Exclude the current owner from the selectable list:
File reference: TransferOwnership.swift

Step 4: Perform Ownership Transfer

Call the API, emit event, and exit the group:
File reference: TransferOwnership.swift

Step 5: Manage Loading State

Provide visual feedback during network calls:
File reference: TransferOwnership.swift

Complete Implementation

Here’s the complete TransferOwnership class:

Customization Options

Title Text

Replace localization key with custom string:

Spinner Style

Adjust spinnerView.style and color using CometChatTheme:

Error Handling

Customize error alerts in the onError closure:

Edge Cases

ScenarioHandling
Empty member listShow an informative empty state when no eligible members exist
Network failuresDisable proceed button until connection restores
Blocked membersExclude or disable blocked users from selection

Error Handling

Error TypeSolution
Transfer failuresPresent UIAlertController with retry option
Unexpected statesEnsure removeSpinnerView() always executes in defer

Feature Matrix

FeatureMethod / ComponentFile(s)
Launch transfer flowshowTransferOwnership(for:)GroupDetailsViewController.swift
Single-member selectionselectionMode = .singleTransferOwnership.swift
Filter out current ownerreloadData() overrideTransferOwnership.swift
Execute API transferCometChat.transferGroupOwnership()TransferOwnership.swift
Show/hide loading indicatoraddSpinnerView(), removeSpinnerView()TransferOwnership.swift

Groups

Display and manage groups

Group Members

View and manage group membership

Group Chat Guide

Complete group management guide