Skip to main content
Quick Reference for AI Agents & Developers
  • Transfer ownership: CometChat.transferGroupOwnership(UID:GUID:onSuccess:onError:)
  • Permission: Only current group owner can transfer ownership
  • Note: Owner must transfer ownership before leaving the group
  • Related: Leave Group · Change Member Scope · Groups Overview

Transfer Group Ownership

In other words, as a logged-in user, how do I transfer the ownership of any group if I am the owner of the group? In order to transfer the ownership of any group, the first condition is that you must be the owner of the group. In case you are the owner of the group, you can use the transferGroupOwnership() method.
The owner is not allowed to leave the group. If you as the owner would like to leave the group, you will have to transfer your ownership first to any other member of the group and only then you will be allowed to leave the group.

Method Parameters

ParameterTypeDescription
UIDStringThe UID of the new owner
GUIDStringThe GUID of the group
let uid = "cometchat-uid-2"
let guid = "cometchat-guid-1"

CometChat.transferGroupOwnership(UID: uid, GUID: guid, onSuccess: { (success) in
    print("Ownership transferred: \(success)")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier of the new owner. Example: "cometchat-uid-2"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Success Response:
ParameterTypeDescription
successStringSuccess message. Example: "Group ownership transferred successfully"
After Transfer:
EffectDescription
New OwnerHas full admin privileges and ownership
Previous OwnerBecomes an admin (not owner)
Leave GroupPrevious owner can now leave the group
EventOther members receive onOwnershipChanged event
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GROUP_NOT_JOINED"
errorDescriptionStringHuman-readable error message. Example: "The user is not a member of the group"
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier of the new owner. Example: "cometchat-uid-2"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Error Response:
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_PERMISSION_DENIED"
errorDescriptionStringHuman-readable error message. Example: "User is not the owner of the group"
Only the current owner can transfer ownership.
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier (same as current owner). Example: "cometchat-uid-1"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Error Response:
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_CANNOT_TRANSFER_TO_SELF"
errorDescriptionStringHuman-readable error message. Example: "Cannot transfer ownership to yourself"

Real-Time Ownership Changed Events

In other words, as a member of a group, how do I know when ownership is transferred? In order to receive real-time events whenever group ownership changes, you will need to implement the onOwnershipChanged() method of the CometChatGroupDelegate.
class ViewController: UIViewController, CometChatGroupDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        CometChat.groupdelegate = self
    }
    
    func onOwnershipChanged(group: Group, newOwner: GroupMember) {
        print("Ownership changed in group: \(group.name ?? "")")
        print("New owner: \(newOwner.name ?? "")")
    }
}

onOwnershipChanged Parameters

ParameterTypeDescription
groupGroupGroup where ownership changed
newOwnerGroupMemberThe new owner of the group
Event Trigger: Received via CometChatGroupDelegate.onOwnershipChanged(group:newOwner:)group (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "cometchat-guid-1"
nameString?Group display name. Example: "My Group"
ownerString?UID of the new owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 5
newOwner (GroupMember Object):
ParameterTypeDescription
uidString?Unique identifier of the new owner. Example: "cometchat-uid-2"
nameString?Display name of the new owner. Example: "George Alan"
avatarString?URL to the new owner’s avatar. Example: "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp"
scopeMemberScopeNew owner’s scope. Example: .admin

Missed Ownership Changed Events

In other words, as a member of a group, how do I know when ownership is transferred when my app is not running? When you retrieve the list of previous messages if ownership has been transferred for any group that the logged-in user is a member of, the list of messages will contain an Action message.

Action Message Properties (for missed events)

PropertyTypeDescription
actionString"ownershipChanged"
actionOnUserNew owner
actionByUserPrevious owner who transferred
actionForGroupGroup where change occurred

Common Error Codes

Error CodeDescriptionResolution
ERR_GROUP_NOT_FOUNDGroup with specified GUID does not existVerify the GUID is correct
ERR_UID_NOT_FOUNDTarget user does not existVerify the user UID
ERR_GROUP_NOT_JOINEDUser is not a member of the groupJoin the group first
ERR_NOT_A_MEMBERTarget user is not a member of the groupAdd user to group first
ERR_PERMISSION_DENIEDLogged-in user is not the group ownerOnly owner can transfer ownership
ERR_CANNOT_TRANSFER_TO_SELFCannot transfer ownership to yourselfSpecify a different user