Stream Chat Swift SDK

repository·develop·Indexed 21 days ago

https://github.com/getstream/stream-chat-swift

Official iOS SDKs for building chat and messaging applications. It offers three levels of integration: a Low Level Client (LLC) for custom UIs, a UIKit SDK (StreamChatUI) for iOS 13+, and a SwiftUI SDK (StreamChatSwiftUI) for iOS 14+. Features include offline support, rich media, AI integration, and native Swift APIs with Combine and Structured Concurrency support.

Tokens
1.9K
Snippets
1
Records
13
Agent score
75%

What's inside stream-chat-swift

  1. Overview of Stream Chat Swift SDK

    develop

    Stream Chat Swift is the official iOS SDK for building chat and messaging applications. It provides two main layers of functionality:

    1. Low Level Client (LLC): A type-safe Swift API for managing chat logic, including offline support (browsing channels and sending messages while offline) and first-class support for Combine via Combine wrappers.
    2. UI Components: Reusable UI elements available for both UIKit and SwiftUI.

    Key characteristics:

    • Native Behavior: UI elements respect system settings like tintColor, layoutMargins, light/dark mode, and dynamic font sizes.
    • Platform Support: Supports iOS 13+.
    • Open Source: The implementation is fully open-source.
  2. Explore Stream's ecosystem: Video, Feeds, and AI

    develop

    Stream provides specialized SDKs that integrate with the Chat SDK:

    • Video SDK: For seamless video integration (stream-video-swift).
    • Feeds SDK: For activity feeds integration (stream-feeds-swift).
    • AI Components: Specialized SwiftUI components for AI chat interfaces, featuring natural streaming animations, markdown/code rendering, thinking indicators, and flexible composers (stream-chat-swift-ai).
  3. Choose the right Stream Chat SDK for your project

    develop

    Stream Chat provides three different levels of integration depending on your UI requirements and target iOS version:

    1. Low Level Client (LLC) / StreamChat SDK: A pure logic client with no UI components. Use this if you want to build a completely custom user interface from scratch.
    2. UIKit SDK / StreamChatUI SDK: A collection of reusable UIKit components. This is the recommended choice for most use cases and supports iOS 13 and above.
    3. SwiftUI SDK / StreamChatSwiftUI SDK: A collection of reusable SwiftUI components. This is available in a separate repository (stream-chat-swiftui) and requires iOS 14 and above.

    All SDKs feature offline support, native Swift APIs, and first-class support for Combine and Structured Concurrency.

  4. Understand the difference between StreamChat and StreamChatUI

    develop

    The repository provides two distinct ways to build chat experiences:

    StreamChat (Low Level)

    Use StreamChat if you want to build a completely custom UI from scratch. It provides the core logic, including:

    • Local database logic
    • API calls
    • Chat event handling

    StreamChatUI (High Level)

    Use StreamChatUI if you want a ready-made, fully-featured UI with built-in components. It provides UIKit components that run on top of the StreamChat core logic, offering high-level functionality with customizability options.

  5. Configure Authentication in the Sample App

    develop

    The sample app includes a login screen to configure authentication and user details. You can use the following methods to authenticate:

    • Pre-existing User: The app comes pre-configured with a test API Key and a user. You can press the refresh icon (↻) on the top right to cycle through different pre-existing users.
    • JWT (JSON Web Token): Authenticate using a generated JWT. To generate a JWT, you need your app's secret and a server-side SDK or the Stream JWT generator.
    • Guest: Authenticate as a guest user.
    • Development Token: Use a development token (note: this must be enabled in your Stream Chat dashboard).
  6. Install and run the Stream Chat UI Demo App

    develop

    To preview the features of the Stream Chat UI or use the demo for testing purposes, follow these steps to set up the official demo app:

    1. Clone the repository.
    2. Open StreamChat.xcodeproj in Xcode.
    3. Allow Swift Package Manager to install the necessary dependencies.
    4. Select the DemoApp target in Xcode and run it on your preferred iOS device or simulator.
    1. Clone this repository.
    2. Open `StreamChat.xcodeproj` on Xcode.
    3. Wait for Swift Package Manager to install dependencies.
    4. Select the `DemoApp` target and run in your preferred device.
  7. Run the Stream Chat Sample App

    develop

    The StreamChatSample project is an official sample application used to preview features and test different design patterns. It demonstrates how to use both the StreamChat (low-level) and StreamChatUI (high-level) SDKs.

    To run the sample:

    1. Close the current repository.
    2. Open StreamChat.xcodeproj in Xcode.
    3. Wait for Swift Package Manager to resolve and install all dependencies.
    4. Select the Sample target in the Xcode scheme selector.
    5. Run the project on your preferred simulator or device.
  8. Navigate the Stream Chat UI Demo App

    develop

    Once logged in, the app follows a standard chat flow:

    1. Channel List: You are directed to the ChatChannelListViewController. This screen shows an infinite scrolling list of channels the user belongs to, including avatars, unread indicators, last message previews, and timestamps. You can create new channels via the top-right button or delete channels by swiping left on them.
    2. Chat Screen: Tapping a channel opens the ChatChannelViewController. This screen provides an infinite scrolling list of messages, a channel header, rich media support (including GIFs), a message composer with file attachment support, and message reactions (via long-press).
  9. Integrate Stream Chat with Objective-C

    develop
    If your project uses Objective-C, you can still integrate the Stream Chat SDKs. However, because the SDK is written in Swift, any UI customizations must be performed by subclassing the components in Swift first, and then exposing those Swift subclasses to your Objective-C code.
  10. Log in to the Stream Chat UI Demo App

    develop

    The demo app provides two ways to log in:

    • Pre-configured Users: The initial login screen displays a list of users pre-configured to interact with the test server. Simply tap a user to log in.
    • Custom Credentials: Tap "Advanced options" at the bottom of the user list to log in to a different server using custom credentials.

    Note: To log in with custom credentials, you must provide a valid user token (JWT). You can generate this using your app's secret via a server-side SDK or the Stream JWT generator.

  11. Configure Client Initialization Options

    develop

    The login screen in the sample app provides additional options to control how the StreamChat client is initialized:

    • Local Storage: Toggle whether to use local storage for the client.
    • Flush on Start: Option to flush local storage when the app starts.
    • Region: Select the specific region your app is hosted in.