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. Our iOS SDK provides you with many helpful methods to build a chat app with diverse features.
This Quick Start page will help newcomers and even our veteran users familiarize themselves with basic SDK functionalities and logic. It lets you go through the easy steps of implementing QuickBlox in your app.
QuickBlox iOS SDK supports both Swift and Objective-C programming languages.
Before you begin
Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
Start with sample apps
If you are just starting your app and developing it from scratch, we recommend to use our sample apps. Chat sample and Video chat sample are ready-to-go apps with appropriate functionality and simple enough that even novice developers will be able to understand them.
You can clone the repository using the link below:
git clone https://github.com/QuickBlox/quickblox-ios-sdk.git
Chat sample
To run a code sample, follow the steps below:
- Install CocoaPods to manage project dependencies.
sudo gem install cocoapods
- Clone repository with the sample code.
- Open a terminal and enter the command below in your project path to integrate QuickBlox into the sample.
pod install
- Get application credentials and get
applicationID
,authKey
,authSecret
, andaccountKey
. - Put the received credentials in
AppDelegate
file located in the root directory of your project.
QBSettings.applicationID = 92
QBSettings.authKey = "wJHdOcQSxXQGWx5"
QBSettings.authSecret = "BTFsj7Rtt27DAmT"
QBSettings.accountKey = "7yvNe17TnjNUqDoPwfqp"
[QBSettings setApplicationID:92];
[QBSettings setAuthKey:@"wJHdOcQSxXQGWx5"];
[QBSettings setAuthSecret:@"BTFsj7Rtt27DAmT"];
[QBSettings setAccountKey:@"7yvNe17TnjNUqDoPwfqp"];
- Run the code sample.
Video chat sample
- Install CocoaPods to manage project dependencies.
sudo gem install cocoapods
- Clone repository with the sample code.
- Open a terminal and enter the command below in your project path to integrate QuickBlox into the sample.
pod install
- Get application credentials and get
applicationID
,authKey
,authSecret
, andaccountKey
. - Put the received credentials in
AppDelegate
file located in the root directory of your project.
QBSettings.applicationID = 92
QBSettings.authKey = "wJHdOcQSxXQGWx5"
QBSettings.authSecret = "BTFsj7Rtt27DAmT"
QBSettings.accountKey = "7yvNe17TnjNUqDoPwfqp"
[QBSettings setApplicationID:92];
[QBSettings setAuthKey:@"wJHdOcQSxXQGWx5"];
[QBSettings setAuthSecret:@"BTFsj7Rtt27DAmT"];
[QBSettings setAccountKey:@"7yvNe17TnjNUqDoPwfqp"];
- Run the code sample.
Get application credentials
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:
- Register a new account following this link. Type in your email and password to sign in. You can also sign in with your Google or Github accounts.
- Create the app clicking New app button.
- Configure the app. Type in the information about your organization into corresponding fields and click Add button.
- Go to Dashboard => YOUR_APP => Overview section and copy your Application ID, Authorization Key, Authorization Secret, and Account Key .
Requirements
The minimum requirements for QuickBlox iOS SDK are:
- iOS 12.
- CocoaPods 1.1.
- Xcode 11.
Install QuickBlox SDK into your app
CocoaPods must be installed.
- Create a
Podfile
. Project dependencies should be managed by CocoaPods. Create this file in the same directory with your project.
pod init
touch Podfile
open -e Podfile
- Open the created
Podfile
and enter the following code lines into it. Specify the SDK version being installed.
platform :ios, "12.0"
use_frameworks!
target 'MyApp' do
pod 'QuickBlox', '~> 2.17.5'
pod 'Quickblox-WebRTC', '~> 2.7.4'
end
- Install QuickBlox dependencies in your project.
pod install
- Import headers to start using Quickblox frameworks.
import Quickblox
import QuickbloxWebRTC
#import <Quickblox/Quickblox.h>
#import <QuickbloxWebRTC/QuickbloxWebRTC.h>
Send your first message
Initialize QuickBlox SDK
Initialize the framework with your application credentials. As a result, your application details are stored in the server database and can be subsequently identified on the server.
Initialize your app on QuickBlox server by passing applicationID
, authKey
, authSecret
, accountKey
via AppDelegate file located in the root directory of your project:
QBSettings.applicationID = 92
QBSettings.authKey = "wJHdOcQSxXQGWx5"
QBSettings.authSecret = "BTFsj7Rtt27DAmT"
QBSettings.accountKey = "7yvNe17TnjNUqDoPwfqp"
[QBSettings setApplicationID:92];
[QBSettings setAuthKey:@"wJHdOcQSxXQGWx5"];
[QBSettings setAuthSecret:@"BTFsj7Rtt27DAmT"];
[QBSettings setAccountKey:@"7yvNe17TnjNUqDoPwfqp"];
Authorize user
Now, it is time to login with the user. You need to run a user session to be able to edit user data, for example, retrieve user data, view user contact list, etc. To create a user session, call the logIn()
method and pass userLogin
and userPassword
parameters to it.
QBRequest.logIn(withUserLogin: "userLogin", password: "userPassword", successBlock: { (response, user) in
}, errorBlock: { (response) in
})
[QBRequest logInWithUserLogin:@"userLogin" password:@"userPassword" successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull tUser) {
} errorBlock:^(QBResponse * _Nonnull response) {
}];
Connect to Chat
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 user.id
and user.password
to it.
QBChat.instance.connect(withUserID: user.id, password: user.password, completion: { (error) in
})
[QBChat.instance connectWithUserID:currentUser.ID password:currentUser.password completion:^(NSError * _Nullable error) {
}];
Create dialog
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 chat. Create a QBChatDialog
instance and specify dialogID
, type
, and occupantIDs
. Call the createDialog() method and pass the QBChatDialog
instance within it. Consequently, the server assigns the ID to the dialog and responds with dialogID
.
let dialog = QBChatDialog(dialogID: nil, type: .private)
dialog.occupantIDs = [34]
QBRequest.createDialog(dialog, successBlock: { (response, createdDialog) in
}, errorBlock: { (response) in
})
QBChatDialog *dialog = [[QBChatDialog alloc] initWithDialogID:nil type:QBChatDialogTypePrivate];
dialog.occupantIDs = @[@34]; // an ID of opponent
[QBRequest createDialog:dialog successBlock:^(QBResponse * _Nonnull response, QBChatDialog * _Nonnull createdDialog) {
} errorBlock:^(QBResponse * _Nonnull response) {
}];
Make sure to set
nil
value for thedialogID
parameter. Once the server verifies the user who is going to participate in the dialog byoccupantID
, it creates a dialog by the specified dialogtype
and assignsdialogID
. Consequently, the assigneddialogID
is returned by the server.
In case, a wrong dialog
type
is passed to the server, the server responds with 422 error code.
Receive messages
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 addDelegate()
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.
QBChat.instance.addDelegate(self)
[QBChat.instance addDelegate: self];
Implement QBChatDelegate()
methods you need in your chat controller.
/// MARK: - QBChatDelegate
extension YourViewController: QBChatDelegate {
// MARK: - Manage chat receive message callback's
func chatRoomDidReceive(_ message: QBChatMessage, fromDialogID dialogID: String) {
// Called whenever group chat dialog did receive a message.
// !!!note Will be called on both recipients' and senders' device (with corrected time from server)
}
func chatDidReceive(_ message: QBChatMessage) {
// Called whenever new private message was received from QBChat.
// !!!note Will be called only on recipient device
}
}
/// MARK: - QBChatDelegate
// MARK: - Manage chat receive message callback's
- (void)chatDidReceiveMessage:(QBChatMessage *)message {
// Called whenever new private message was received from QBChat.
// !!!note Will be called only on recipient device
}
- (void)chatRoomDidReceiveMessage:(QBChatMessage *)message fromDialogID (NSString*)dialogID {
// Called whenever group chat dialog did receive a message.
// !!!note Will be called on both recepients' and senders' device (with corrected time from server)
}
Send message
To send a message, create QBChatMessage
instance and specify a text of the message using text
parameter. Call the send()
method and pass the created QBChatMessage
instance within it.
let message = QBChatMessage()
message.text = "How are you today?"
let privateDialog = ...
privateDialog.send(message) { (error) in
}
QBChatMessage *message = [[QBChatMessage alloc] init];
message.text = @"How are you today?";
QBChatDialog *privateDialog = ...;
[privateDialog sendMessage:message completionBlock:^(NSError * _Nullable error) {
}];
Updated 28 days ago
What's Next
Setup |