Appearance
Swift SDK - Chat API
About 759 wordsAbout 3 min
Comprehensive code examples for the Stream chat swift SDK.
Quick Navigation
- Chat (56 methods)
- Common (43 methods)
- Moderation (12 methods)
- Push & Notifications (9 examples)
- State Layer (9 examples)
- Types Reference - interfaces for API requests/responses
Overview
This documentation covers 111 API methods across 3 categories, plus 18 examples for Push & Notifications and State Layer.
Installation
// Add to Package.swift dependencies:
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.0.0")Basic Setup
import StreamChat
let config = ChatClientConfig(apiKeyString: "YOUR_API_KEY")
let client = ChatClient(config: config)
client.connectUser(
userInfo: UserInfo(id: "john"),
token: .init(stringLiteral: "<user_token>")
)Categories
Chat
queryChannels()- Access a list of communication channels available in your account, facilitating efficient management and selection for your campaigns.deleteChannels()- Asynchronously remove specific channels from your account, helping you maintain an organized and relevant channel list without immediate blocking.markDelivered()- Update the delivery status of messages sent through a channel, ensuring accurate tracking and reporting of message delivery outcomes.markChannelsRead()- Mark all messages in selected channels as read, allowing you to streamline communication management and reduce notification clutter.getOrCreateDistinctChannel()- Retrieve an existing channel or create a new one based on unique identifiers, simplifying the process of managing distinct communication threads.- ... and 51 more methods
Common
getApp()- Retrieve the current application settings to understand or verify the configuration. Use this method when you need to view the existing app settings without making changes.listBlockLists()- Get a list of all existing block lists to review or manage them. Use this method when you need an overview of current block lists.createBlockList()- Create a new block list to restrict certain content or users as per your criteria. Use this method when setting up a new block list for moderation or content control.updateBlockList()- Modify an existing block list to add or remove entries as needed. Use this method when updating the criteria or contents of a block list.deleteBlockList()- Remove a specific block list that is no longer needed. Use this method when you want to delete a block list to stop enforcing its restrictions.- ... and 38 more methods
Moderation
appeal()- Submit a request to challenge a moderation decision if you believe it was incorrect or unfair, helping to ensure accurate content moderation.getAppeal()- Retrieve details of a specific appeal you have submitted, allowing you to track the status and outcome of the appeal process.queryAppeals()- Search and list submitted appeals based on specific criteria, enabling you to manage and review multiple appeals efficiently.ban()- Use this method to prohibit a user from accessing your service due to violations, ensuring a safe and respectful environment.upsertConfig()- Create a new or update an existing moderation policy configuration to tailor content review processes to your specific needs.- ... and 7 more methods
Push & Notifications
- Push Configuration - APN - Configure push notifications using Apple Push Notification service (APN). Set up the APN configuration on the
ChatClientConfigto enable push delivery for chat messages. - Push Configuration - Firebase - Configure push notifications using Firebase Cloud Messaging (FCM). Set up the Firebase configuration on the
ChatClientConfigto enable Firebase-based push delivery. - AppDelegate Setup - Set up your
AppDelegateto handle push notification registration and forward the device token to the Stream Chat SDK. - Register Device - Register a device for push notifications. Use
addDevice(token:)on theCurrentUserControllerto register the APN device token. - Remove Device - Remove a registered device to stop receiving push notifications. Use
removeDevice(id:)on theCurrentUserControllerwith the device identifier. - ... and 4 more examples
State Layer
- ChatChannelController - Setup & Observation - Create and observe a
ChatChannelControllerfor a specific channel. The controller provides reactive access to channel data, messages, and members. Set a delegate to receive callbacks when channel state changes. - ChatChannelListController - Setup & Observation - Create and observe a
ChatChannelListControllerto query and monitor a list of channels. The controller automatically updates when channels are added, removed, or modified. - Message List Observation - Observe messages in a channel using the
ChatChannelController. Messages are automatically sorted and updated in real time as new messages arrive or existing messages are modified. - Typing Indicators - Observe and send typing indicators in a channel. Use
sendKeystrokeEvent()to notify others that the current user is typing, and observe typing events through the channel controller delegate. - Read State & Unread Counts - Observe read state and unread counts for channels. Use the channel controller to access per-channel unread counts and the current user controller for total unread counts across all channels.
- ... and 4 more examples
Generated from Stream OpenAPI specification