iOS Introduction
Confused about "iOS Introduction"?
Let us know how we can improve our documentation:
Before reviewing the Chat API docs, we recommend having a look at the tutorials and sample apps.
We provide a low-level and two UI components SDKs: UIKit and SwiftUI. UI components SDKs provide a ready-made UI with a aim of having high level of customisation and reusability.
Main Features
Copied!Confused about "Main Features"?
Let us know how we can improve our documentation:
UIKit
andSwiftUI
SDKs use native patterns and paradigms from respective UI frameworks: The API follows the design of native system SDKs. It makes integration with your existing code easy and familiar.First-class support for
Combine
andStructured Concurrency
: Refer to getting started guides for Combine and Structured Concurrency.Offline support: Browse channels and send messages while offline.
Familiar behaviour: The UI elements are good platform citizens and behave like native elements; they respect
tintColor
,layoutMargins
, light/dark mode, dynamic font sizes, etc.Swift native API: Uses Swift's powerful language features to make the SDK usage easy and type-safe.
Fully open source implementation: You have access to the source code of our SDKs on GitHub: UIKit and SwiftUI.
Supports iOS 13:+ We proudly support older versions of iOS, so your app can stay available to almost everyone.
Overview
Copied!Confused about "Overview"?
Let us know how we can improve our documentation:
Our SDKs provide 3 different ways for integrating with Your app: low level client (LLC), UIKit SDK, and SwiftUI SDK. LLC is a data layer responsible of managing offline state and handling API requests. Use it for building fully custom UIs. UIKit and SwiftUI SDKs come with ready-made UI components built using respective UI frameworks. UI components are highly customisable and reusable and therefore, are the best way for bringing the chat UI to Your app. To learn how to use our pre-built UI components, see the iOS Chat Tutorial or read the UI SDK docs.
If you want to learn the basics of using our low-level client without the UI components, keep reading.
Installation
Copied!Confused about "Installation"?
Let us know how we can improve our documentation:
You can add Stream Chat to your Xcode project using Swift Package Manager, CocoaPods, and XCFrameworks. Please head over to our installation documentation here and start building a world class chat UI.
Chat Client
Copied!Confused about "Chat Client"?
Let us know how we can improve our documentation:
Let's get started by initializing the client and setting the current user:
The above snippet is for an in-browser or mobile integration. Server-side API calls are a little different, but this is covered in detail later in the documentation.
Channels
Copied!Confused about "Channels"?
Let us know how we can improve our documentation:
Let’s continue by initializing your first channel. A channel contains messages, a list of people that are watching the channel, and optionally a list of members (for private conversations). The example below shows how to set up a channel to support chat for a group conversation using completion handler based controllers and the async-await supported state-layer:
The first two arguments are the Channel Type and the Channel ID (messaging
and general
in this case). You can also use `createDirectMessageChannelWith` creator to create a channel without a cid, cid will be generated based on the members by the backend. The channel type controls the settings we’re using for this channel.
There are 5 default types of channels:
- livestream
- messaging
- team
- gaming
- commerce
These five options above provide you with the most sensible defaults for those use cases. You can also define custom channel types if Stream Chat defaults don’t work for your use-case.
The third argument is an object containing the channel data (`extraData`). You can add as many custom fields as you would like as long as the total size of the object is less than 5KB.
Messages
Copied!Confused about "Messages"?
Let us know how we can improve our documentation:
Now that we have the channel set up, let's send our first chat message:
Similar to users and channels, the send method allows you to add custom fields. When you send a message to a channel, Stream Chat automatically broadcasts it to all the people that are watching this channel in real-time.
This is how you can listen to message list changes on the client-side:
Conclusion
Copied!Confused about "Conclusion"?
Let us know how we can improve our documentation:
Now that you understand the building blocks of a fully functional chat integration, let’s move on to the next sections of the documentation, where we dive deeper into details on each of the available resources and the methods for interacting with them.