Tutorial: Build an iOS chat app with PubNub

This tutorial showcases how you can get easily build a scalable chat app for iOS with PubNub.

Step 01

Build a Chat App with the PubNub iOS SDK

This tutorial will walk you through developing a basic chat application in Swift using PubNub.  

This tutorial will focus on the Swift SDK and not the community-supported chat UI components designed for iOS.  

The source code for this application can be found on Github at https://github.com/PubNubDevelopers/GettingStarted-Swift-SDK-Tutorial 

Prerequisites

Before running this application, be sure you have the following installed:

  • XCode. The application was created with version 13.4.1 of Xcode but any recent version should work.

Download Source Application

In a terminal, navigate to an empty folder.  Enter the following command to clone the repository:

git clone https://github.com/PubNubDevelopers/GettingStarted-Swift-SDK-Tutorial.git cd GettingStarted-Swift-SDK-Tutorial

The main git branch contains the completed version of this tutorial.  If you would like to follow along, please checkout the following branch:

git checkout tutorial_step_0

Step 02

Create keys

Demo keys

You're ready to go!

We’ve assigned demo keys which are set up to support the features of this tutorial app. These will be active for 72 hours but you can sign up for a free account at the end of the tutorial to create your own permanent keys.

The demo keys have the following functionality activated ready for your application:

  • Presence

  • Message Persistence You will be able to see user’s message history and meta data.

  • Stream Controller You will be able to receive messages against a group of channels, or post one message to multiple channels.

  • App Context This allows you to manage the metadata of your users and channels.

My own keys

To use your own keys, create a free account and a keyset with Presence, Message Persistence, Stream Controller, and App Context on.

You can create the keyset with the Admin API, PubNub's REST API for account management. An Account Owner or Account Admin creates a Service Integration and its API key in the Admin Portal under Organization Settings → API Management. Give it read & write access to apps and keysets, plus read access to secret keys, which keyset creation requires. With that key, create an app, then create a keyset in it and pass the keyset's configuration in the same request. The response includes the publish and subscribe keys. See the Admin API documentation for the requests and keyset settings.

Step 03

Build and run

Step 04

Congratulations - what's next?

Chat SDK Documentation

Chat OverviewSwift SDK DocsChat Developer Path

Live Tour

Start the live coding tour

Developing to a tight deadline? Explore Chat Components

Chat Components IntroductionChat Components Documentation (iOS)

Ready to get beyond Proof of Concept?

Schedule a 15 minute chat with one of our experts to get your project moving

Talk to an Expert
Keep building

Take it to production on your own keys

Create a free PubNub account to get permanent keys for this app.