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

  • A UIKit-based iOS project.
  • CometChat UIKit for iOS v5 installed via CocoaPods or Swift Package Manager.
  • CometChat SDKs (CometChatSDK, CometChatUIKitSwift) integrated.
  • Logged-in user with CometChat.login().
  • UINavigationController or modal presentation flow set up.
  • Group context (GUID) available when invoking the transfer screen.

Components

ComponentResponsibility
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

1. Present Transfer Ownership Screen

Show the ownership transfer UI modally.
func showTransferOwnership(for group: Group) {
  let transferVC = TransferOwnership()
  transferVC.set(group: group)
  let nav = UINavigationController(rootViewController: transferVC)
  present(nav, animated: true)
}
File reference:
GroupDetailsViewController.swift

2. Configure Single Selection Mode

Restrict selection to one member and capture selection.
override func viewDidLoad() {
  selectionMode = .single
  super.viewDidLoad()
  title = "OWNERSHIP_TRANSFER".localize()
  onSelectedItemProceed = { [weak self] users in
    if let newOwner = users.first {
      self?.transferOwnership(to: newOwner)
    }
  }
}
File reference:
TransferOwnership.swift

3. Load & Filter Member List

Exclude the current owner from the selectable list.
override func reloadData() {
  super.reloadData()
  viewModel.reload = { [weak self] in
    guard let self = self else { return }
    let currentUID = CometChat.getLoggedInUser()?.uid
    self.viewModel.groupMembers.removeAll { $0.uid == currentUID }
    DispatchQueue.main.async {
      self.removeLoadingView()
      self.removeErrorView()
      self.reload()
      if self.viewModel.groupMembers.isEmpty { self.showEmptyView() }
    }
  }
}
File reference:
TransferOwnership.swift

4. Perform Ownership Transfer

Call the API, emit event, and exit the group.
func transferOwnership(to member: GroupMember) {
  addSpinnerView()
  let uid = member.uid ?? ""
  let guid = viewModel.group.guid

  CometChat.transferGroupOwnership(UID: uid, GUID: guid) { [weak self] _ in
    DispatchQueue.main.async {
      // Update local state
      self?.viewModel.group.owner = uid
      CometChatGroupEvents.ccOwnershipChanged(group: self!.viewModel.group, newOwner: member)
      self?.leaveGroupCallback?()
      self?.removeSpinnerView()
      self?.dismiss(animated: true)
    }
  } onError: { [weak self] error in
    DispatchQueue.main.async {
      self?.removeSpinnerView()
      // TODO: Show error alert
    }
  }
}
File reference:
TransferOwnership.swift

5. Manage Loading State

Provide visual feedback during network calls.
func addSpinnerView() {
  spinnerView.startAnimating()
  navigationItem.rightBarButtonItem = UIBarButtonItem(customView: spinnerView)
}

func removeSpinnerView() {
  spinnerView.stopAnimating()
  navigationItem.rightBarButtonItem = nil
}
File reference:
TransferOwnership.swift

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.

Filtering & Edge Cases

  • Empty Member List: Show an informative empty state when no eligible members exist.
  • Network Failures: Disable proceed button until connection restores.
  • Blocked Members: Exclude or disable blocked users from selection.

Error Handling

  • Transfer Failures: Present UIAlertController with retry option.
  • Unexpected States: Ensure 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

Full Sample App

Explore the transfer ownership feature in context: GitHub → SampleApp

UIKit Source Code

Review the implementation: TransferOwnership.swift