Build

How to Build an iOS Chat App for Swift

Chandler Mayo on Sep 5, 2022
How to Build an iOS Chat App for Swift

Please note that PubNub will discontinue support for Chat Components on January 1, 2025. They will remain open-source and community-maintained but will no longer receive feature updates from PubNub.

This video will cover PubNub’s iOS Chat Components and how to integrate them into any other iOS app. This video is a continuation of our previous iOS Chat Components Release: Build Mobile Chat Experiences Tutorial. However, instead of starting from scratch we’ll take a second look at how iOS Chat Components work and some additional improvements we made.

We’ll start by taking a look at how PubNub iOS Chat Components have been integrated into an existing sample app. Then, we’ll show you how to configure and customize the components. If you’re not yet familiar with PubNub’s iOS Chat Components, check out our product release announcement here.

Let’s dive into the tutorial—watch below to see a demo of PubNub’s iOS Chat Components and learn about how your app can benefit from them, then keep reading to see how you can get your FREE API keys so you can start building with these components.  

PubNub’s iOS Chat Components Overview: Build an iOS Swift Chat App

PubNub’s iOS Chat Components empower all kinds of developers to create dynamic chat experiences – without the time spent building chat when you could be focused on creating other parts of your application. If you are making a chat app from scratch, migrating your chat widget, or adding features to your existing iOS application—our ready-to-use iOS message components provide you with the building blocks to easily add the features your users expect from a chat experience. There’s no need to create and maintain the infrastructure yourself.

Our set of iOS Chat Components are packed with the features you’d expect from any chat experience:

  • User and Channel Metadata: Fetch metadata about users, channels, and memberships from App Context storage using custom hooks.

  • Channel Subscription Management: Automatic subscriptions to current channel and optional subscriptions to other channels and channel groups.

  • Messages: Publish and listen to text messages and fetch history for each channel.

  • Presence: Fetch currently present users and listen to new presence events like a user subscribing or leaving.

  • Typing Indicators: Typing indicators displayed as text notifications or messages.

  • Persistent Data Storage: Store messages, channels, and users locally for offline use.

Our iOS Chat Components are modifiable to your requirements so you’re free to create chat for various use cases all with different functionalities and customizable looks.

How can you use PubNub’s Chat Components to build an iOS Swift chat app?

PubNub is used for real-time message delivery, metadata, presence, and other chat-related data to facilitate the actions within the chat UI Components. iOS Chat Components have PubNub services fully incorporated and are ready to use.

The following chat components are included with PubNub iOS Chat Components:

  • MemberList: List of users with properties like names, titles, or avatars.

  • MessageList: List of messages with sender details.

  • MessageInput: Field to send messages to chat rooms. When you type this component also triggers typing indicators for other users.

  • ChannelList: List of channels that represents chat rooms in the application. We won’t be using this component in this tutorial. However, it’s easy to include if it’s necessary in your application.

Chat API Setup for iOS Components

To follow along with our tutorial, you will need a PubNub account, where you will use your PubNub API keys to build a chat application with iOS Chat Components. As a reminder, a PubNub account and API keys are always free.

Here’s how to get started: 

  1. Sign up for a PubNub account.

  2. Sign in to your PubNub Dashboard.

  3. Follow the steps in the video tutorial to configure a chat application with PubNub iOS Chat Components.

What’s Next 

In the above video tutorial, we took a look at how PubNub’s iOS Components are used in an existing Swift app and how to get started setting up a PubNub Account. 

The Weather-Chat app with PubNub iOS Chat Components we build can be found in this repo.

Continue by exploring these additional iOS Chat Components features:

Need some extra help or want to learn more about iOS Chat Components? Get in touch with our sales team to discuss how you can easily build and scale your chat with PubNub.