Overview
GroupDetailsViewController
displays comprehensive group information and actions:
- Group Info: Name, icon, description, and member count.
- Actions: Join/Leave/Delete group.
- Member Management: View members, add members, view banned members.
- Real-Time Updates: Reflects joins, leaves, bans, and ownership changes.
Prerequisites
- A UIKit-based iOS project.
- CometChat UIKit for iOS v5 installed via CocoaPods or Swift Package Manager.
- Valid CometChat App ID, Region, and Auth Key.
- User logged in with
CometChat.login()
. - Navigation stack (
UINavigationController
) configured.
Components
Component | Role |
---|---|
CometChatGroup | Renders group avatar, name, and metadata. |
GroupActionView | Custom view for action buttons (view/add/banned members). |
CometChatMessagesViewController | Opens group chat interface when “Chat” is tapped. |
CometChat.joinGroup() | Joins public or password-protected groups. |
CometChat.leaveGroup() | Leaves the current group. |
CometChat.deleteGroup() | Deletes and exits the group (owners only). |
CometChatGroupMembers | Lists current group members. |
CometChatGroupDelegate | Receives real-time group events. |
Integration Steps
1. Presenting the Group Details Screen
PushGroupDetailsViewController
for a selected group.
HomeScreenViewController.swift
Initializes and presents the details UI with the correct group context.
2. Setting Up the UI
Configure scroll view, header, and action views.GroupDetailsViewController.swift
Lays out the UI components and registers for group events.
3. Enabling Group Action Buttons
Wire up view/add/banned members actions.GroupDetailsViewController.swift
Enables user interaction for member management.
4. Handling Leave and Delete Actions
Provide ownership-aware leave/delete flows.GroupDetailsViewController.swift
Manages group exit, with transfer prompt for owners.
5. Listening for Group Events
Update UI on member joins, leaves, bans, and ownership changes.GroupDetailsViewController.swift
Keeps the group details in sync with back-end events.
Customization Options
- Header Styling: Use
CometChatTheme
to customize fonts, colors, and borders. - Button Labels: Localize or rebrand action texts.
- Avatar Placeholder: Provide fallback initials or default images.
Filtering & Edge Cases
- Private/Protected Groups: Prompt for a password before joining.
- Already a Member: Hide or disable Join button.
- Empty Group: Show an empty state when no members.
- Owner Restrictions: Disable Delete for non-owners.
Error Handling
- Join Failures: Show alert on network or permission errors.
- Leave/Delete Errors: Display retry prompt on API failure.
- Event Errors: Log and notify user if group events fail.
Feature Matrix
Feature | Component / Method | File(s) |
---|---|---|
Show group details | GroupDetailsViewController | GroupDetailsViewController.swift |
View group members | viewMembersView action | GroupDetailsViewController.swift |
Add members | addMembersView action | GroupDetailsViewController.swift |
Ban members | bannedMembersView action | GroupDetailsViewController.swift |
Join group | CometChat.joinGroup() | GroupDetailsViewController.swift |
Leave group | showLeaveGroupAlert() | GroupDetailsViewController.swift |
Delete group | showDeleteGroupAlert() | GroupDetailsViewController.swift |
Real-time updates | CometChatGroupDelegate | GroupDetailsViewController.swift |
Full Sample App
Explore the complete Group Details flow:
GitHub → SampleApp
UIKit Source Code
Browse the Group Details implementation:
GitHub → GroupDetailsViewController.swift