Learn how to install QuickBlox SDK and send your first message.
QuickBlox SDK helps you implement real-time chat, video chat, and push notifications to your app. You can fully concentrate on your mobile app development. QuickBlox iOS SDK supports both Swift and Objective-C programming languages.
If you are just starting your app and developing it from scratch, we recommend to use our sample apps. We use GitHub repositories to make it easy to explore, copy, and modify our code samples. The guide on how to launch and configure the sample app is on GitHub.
Choose the code sample below to jump-start the development.
Choose the code sample below to jump-start the development.
For more samples, head to our Code Samples page. These sample apps are available on GitHub so feel free to browse them there. Just clone the repository and modify the source code for your own projects.
QuickBlox application includes everything that brings messaging right into your application - chat, video calling, users, push notifications, etc. To create a QuickBlox application, follow the steps below:
The minimum requirements for QuickBlox iOS SDK are:
You can install the QuickBlox iOS SDK using either SPM (Swift Package Manager) or CocoaPods.
QuickBlox iOS SDK is available using the [Swift Package Manager] (https://www.swift.org/package-manager/) (SPM) since version 2.18.1 for QuickBlox and since version 2.8.1 for QuickbloxWebRTC.
To add QuickBlox iOS SDK to your project using SPM, you can follow these steps:
For more information on spm customization options, you can refer to the Apple Documentation.
CocoaPods must be installed.
Podfile
. Project dependencies should be managed by CocoaPods. Create this file in the same directory with your project.Podfile
and enter the following code lines into it. Specify the SDK version being installed.Initialize the framework with applicationID
, authKey
, authSecret
, and accountKey
. Add the code below to the AppDelegate file located in the root directory of your project:
Security
It’s not recommended to keep your authKey and authSecret inside an application in production mode, instead of this, the best approach will be to store them on your backend and initialize QuickBlox SDK with applicationId and acountKey only. More details you can find in Initialize QuickBlox SDK without Authorization Key and Secret section.
Now, it is time to log in with the user. To create a user session, call the logIn()
method and pass the user login and user password as arguments to it.
Having authorized a user, you can proceed with connecting to the chat server to start using Chat module functionality. Call the connect()
method and pass the user.id
and user.password
to it.
QuickBlox provides three types of dialogs: 1-1 dialog, group dialog, and public dialog. Learn more about dialogs here.
Let’s create a simple 1-1 dialog. Create a QBChatDialog
instance and set the dialogID
, type
, and occupantIDs
fields. Call the createDialog()
method and pass the dialog
to it as an argument.
To track events in your chat (for example, receive messages, track to whom your messages are delivered and who read them), you must implement the chat delegate methods for your chat controller. Use the addDelegate()
method to add a listener enabling the app to listen to the received messages. In other words, you subscribe to this event using chat delegate in your chat controller.
Implement theQBChatDelegate
methods you need in your chat controller.
To send a message, create QBChatMessage
instance. Set the text of the message. Call the send()
method and pass the message
as an argument to it.
Set the save_to_history
parameter if you want this message to be saved in chat history.