Overview
TheUserDetailsViewController
provides a detailed view of a CometChat user’s profile and key interaction options, including:
- Displaying the user’s avatar, name, and online status.
- Initiating one-on-one chats.
- Starting audio or video calls.
- Blocking or unblocking users.
- Deleting the conversation with the user.
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 authenticated with
CometChat.login()
before presenting the details screen.
Components
Component | Role |
---|---|
CometChatAvatar | Displays user’s profile picture with customizable styling. |
CometChatMessagesViewController | Opens the 1-on-1 chat interface when “Message” is tapped. |
CometChatCallButtons | Initiates audio/video calls (CometChat.startCall() ). |
CometChatUIKit.blockUser() | Blocks the selected user and updates UI accordingly. |
CometChatUIKit.unblockUser() | Unblocks a user if previously blocked. |
Integration Steps
1. Presenting the User Details Screen
Initialize and pushUserDetailsViewController
with the selected user’s data.
UserDetailsViewController.swift
Ensures the details screen loads with the correct user context.
2. Configuring the UI
Arrange avatar, labels, and action buttons on the view.UserDetailsViewController.swift
Applies theme-based styling and updates status label on appearance.
3. Enabling Call Buttons
Add audio and video call buttons if calls SDK is available.UserDetailsViewController.swift
Conditionally shows call options based on SDK availability.
4. Block/Unblock and Delete Actions
Provide block/unblock and delete conversation functionality.UserDetailsViewController.swift
Manages user relationships and conversation lifecycle.
5. Listening for User Events
Update UI in response to status, block, and unblock events.UserDetailsViewController.swift
Keeps profile status and block state in sync with real-time events.
Customization Options
- Avatar Styling: Use
CometChatAvatarStyle
to adjust shape and border. - Button Assets: Replace default icons with custom images.
- Localization: Override button titles and alerts with localized strings.
- Theming: Leverage
CometChatTheme
andCometChatTypography
for fonts and colors.
Filtering & Edge Cases
- Hide block/unblock controls for the logged-in user.
- Disable call buttons if calling is disabled in settings.
- Handle missing or partially loaded user data with fallback UI.
Error Handling
- Fetch Failures: Show error label or dismiss the view.
- Block/Unblock Errors: Present retry alert on API failure.
- Call Failures: Alert user on call initiation error or permission denial.
Feature Matrix
Feature | Component / Method |
---|---|
Display user details | CometChatAvatar , UILabel |
Open chat | CometChatMessagesViewController(user:) |
Audio/video call | CometChat.startCall() via Call Buttons |
Block user | CometChatUIKit.blockUser(uid:) |
Unblock user | CometChatUIKit.unblockUser(uid:) |
Delete conversation | CometChat.deleteConversation() |
Full Sample App
Try the complete sample app for User Details:
GitHub → SampleApp
UIKit Source Code
Explore CometChat UIKit iOS repository:
GitHub → UIKit v5