Follow the instructions below to ensure that QuickBlox iOS SDK runs smoothly with your app.
Before you begin
Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
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.
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>
Run script phase for archiving
Add a Run Script Phase to build phases of your project. Paste the following snippet into the script.
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/QuickbloxWebRTC.framework/strip-framework.sh"
This fixes the known Apple bug that does not allow to publish archives to the App store with dynamic frameworks that contain simulator platforms. Script is designed to work only for archiving.
Add permissions
You can use our SDK in the background mode as well. If you want to receive push notifications when the app goes to background mode, this requires you to add specific app permissions. Under the app build settings, open the Capabilities tab and turn on Remote notifications checkbox only.


If you want to use video calling functionality in the background mode, set the Audio, AirPlay, and Picture in Picture checkboxes.


Initialize QuickBlox SDK
Initialize the framework with your application credentials. Pass Application ID, Authorization Key and Authorization Secret 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"];
Parameters | Description |
---|---|
applicationID | Application identifier. |
authKey | Authorization key. |
authSecret | Authorization secret. |
accountKey | Required to get actual Chat and API |
Initialize with existing token
You can initialize the SDK with an existing QuickBlox token. It can be interesting in cases when you build a big system and you have the server side which generates QuickBlox tokens.
let sessionDetails = QBASession()
sessionDetails.token = "f23d03bd2341a1f923b7d4c1fbee97af1cd296f2"
// updateSessionBlock executes synchronously on background thread and you are allowed to execute synchronous URL request
// and to block a background thread from executing until you receive updated credentials
// by the end of updateSessionBlock you should call startSessionWithDetails: with updated credentials
QBSession.current.start(withDetails: sessionDetails, updateSessionBlock: {
// Execute synchronous URL request to retrieve new token from custom server
// Until the end of this block all the operations will be paused
let updatedSessionDetails = QBASession()
updatedSessionDetails.token = "new token"//new token from custom server
// Start Updated Session
QBSession.current.start(withDetails: updatedSessionDetails)
})
QBASession *sessionDetails = [QBASession new];
sessionDetails.token = @"f23d03bd2341a1f923b7d4c1fbee97af1cd296f2";
// updateSessionBlock executes synchronously on background thread and you are allowed to execute synchronous URL request
// and to block a background thread from executing until you receive updated credentials
// by the end of updateSessionBlock you should call startSessionWithDetails: with updated credentials
[[QBSession currentSession] startSessionWithDetails:sessionDetails updateSessionBlock:{
// Execute synchronous URL request to retrieve new token from custom server
// Until the end of this block all the operations will be paused
QBASession *updatedSessionDetails = [QBASession new];
session.token = @"new token";//new token from custom serve
// Start Updated Session
[[QBSession currentSession] startSessionWithDetails:updatedSessionDetails];
}];
Custom endpoints
To connect QuickBlox SDK to the custom server, you should specify apiEndpoint
and chatEndpoint
in the AppDelegate file located in the root directory of your project.
QBSettings.applicationID = 92
QBSettings.authKey = "wJHdOcQSxXQGWx5"
QBSettings.authSecret = "BTFsj7Rtt27DAmT"
QBSettings.accountKey = "7yvNe17TnjNUqDoPwfqp"
QBSettings.apiEndpoint = "https://yourApi.quickblox.com"
QBSettings.chatEndpoint = "yourChat.quickblox.com"
[QBSettings setApplicationID:92];
[QBSettings setAuthKey:@"wJHdOcQSxXQGWx5"];
[QBSettings setAuthSecret:@"BTFsj7Rtt27DAmT"];
[QBSettings setAccountKey:@"7yvNe17TnjNUqDoPwfqp"];
[QBSettings setApiEndpoint:@"https://yourApi.quickblox.com"];
[QBSettings setChatEndpoint:@"yourChat.quickblox.com"];
Parameters | Description |
---|---|
apiEndpoint | API endpoint. |
chatEndpoint | Chat endpoint. |
For Basic, Startup, and Growth plan users
- Make sure to set
accountKey
to get all correct endpoints.- Make sure to leave
apiEndpoint
andchatEndpoint
fields empty to provide a smooth migration between servers.
For Enterprise plan users
Contact our sales team to get API and Chat endpoint.
Enable logging
Logging functionality allows you to keep track of all events and activities while running your app. As a result, you can monitor the operation of the SDK and improve the debug efficiency. There are 3 logging use cases:
- REST API logging is used to monitor REST API calls.
- Chat logging is used to monitor chat issues.
- WebRTC logging is used to gather issues with video.
REST API logging
Enable REST API calls debug console output using the setLogLevel()
method.
QBSettings.setLogLevel(QBLogLevel.debug)
[QBSettings setLogLevel:QBLogLevelDebug];
A log level determines what information is written to the log. There can be set the following log levels:
Parameters | Description |
---|---|
QBLogLevel.debug | Write full logs (default value). |
QBLogLevelNetwork | Write network logs. |
QBLogLevelInfo | Write information logs. |
QBLogLevelWarnings | Write warning logs. |
QBLogLevelErrors | Write error logs. |
QBLogLevelNothing | Write nothing. Turn off logs. |
Chat logging
Enable a detailed XMPP logging in the console output using the code snippet below.
QBSettings.enableXMPPLogging()
[QBSettings enableXMPPLogging];
Disable XMPP logging using the code snippet below.
QBSettings.disableXMPPLogging()
[QBSettings disableXMPPLogging];
WebRTC logging
Set WebRTC logs using the setLogLevel()
method.
QBRTCConfig.setLogLevel(QBRTCLogLevel.verboseWithWebRTC)
[QBRTCConfig setLogLevel:QBRTCLogLevelVerboseWithWebRTC];
There can be set the following log levels:
Parameters | Description |
---|---|
QBRTCLogLevelVerboseWithWebRTC | Write full QuickBlox WebRTC and WebRTC native logs. Can be helpful to debug some complicated problems with calls. |
QBRTCLogLevelVerbose | Write full QuickBlox WebRTC logs. Basic logs from our framework (default value). |
QBRTCLogLevelInfo | Write information logs. |
QBRTCLogLevelWarnings | Write warning logs. |
QBRTCLogLevelErrors | Write error logs. |
QBRTCLogLevelNothing | Write nothing. Turn off logs. |
Autoreconnect to Chat
QuickBlox Chat runs over XMPP protocol. To receive messages in a real-time mode, the application should be connected to the Chat over XMPP protocol. To enable autoreconnection to Chat, pass autoReconnectEnabled()
as true
.
QBSettings.autoReconnectEnabled = true
QBSettings.autoReconnectEnabled = YES;
By default, autoreconnection functionality is disabled. Set autoreconnection before calling the
login()
method so it could be applied in a current chat.
Message carbons
Message carbons functionality allows for multi-device support. Thus, all user messages get copied to all their devices so they could keep up with the current state of the conversation. For example, a User A has phone running conversations and desktop running conversations. User B has desktop running conversations. When User B sends a message to User A, the message shows on both the desktop and phone of User A.
Enable message carbons
QBSettings.carbonsEnabled = true
[QBSettings setCarbonsEnabled: YES];
Disable message carbons
QBSettings.carbonsEnabled = false
[QBSettings setCarbonsEnabled: NO];
Since message carbons functionality works over XMPP connection, make sure to enable it after the
logIn()
method is called.
Stream management
Stream management has two important features Stanza Acknowledgements and Stream Resumption:
- Stanza Acknowledgements is the ability to know if a stanza or series of stanzas has been received by one's peer. In other words, a reply is requested on every sent message. If the reply is received, the message is considered as delivered.
- Stream Resumption is the ability to quickly resume a stream that has been terminated. So once a connection is re-established, Stream Resumption is executed. By matching the sequence numbers assigned to each Stanza Acknowledgement a server and client can verify which messages are missing and request to resend missing messages.
Set message timeout to enable stream resumption. The preferred resumption time should be set in seconds. If this parameter is greater than 0
, then it is applied, otherwise, it is not applied.
QBSettings.streamManagementSendMessageTimeout = 0
[QBSettings setStreamManagementSendMessageTimeout: 0];
Stream management gets enabled automatically once the
connect()
method is called and disabled once thedisconnect()
method is called.
Custom ICE servers
You can customize a list of ICE servers. By default, WebRTC module will use internal ICE servers that are usually enough, but you can always set your own. WebRTC engine will choose the TURN relay with the lowest round-trip time. Thus, setting multiple TURN servers allows your application to scale-up in terms of bandwidth and number of users. Set up ICE servers in application(_:didFinishLaunchingWithOptions:)
method of AppDelegate.m
.
let username = "login"
let password = "767565gfh865486h548k6586h5868"
let urls = [
"stun:turn.randomserver.example",
"turn:turn.randomserver.example:5677?transport=udp",
"turn:turn.randomserver.example:5677?transport=tcp"
]
guard let server = QBRTCICEServer.init(urls: urls, username: username, password: password) else {
return
}
QBRTCConfig.setICEServers([server])
NSString *userName = @"login";
NSString *password = @"767565gfh865486h548k6586h5868";
NSArray *urls = @[
@"stun:turn.randomserver.example",
@"turn:turn.randomserver.example:5677?transport=udp",
@"turn:turn.randomserver.example:5677?transport=tcp"
];
QBRTCICEServer *server = [QBRTCICEServer serverWithURLs:urls username:userName password:password];
[QBRTCConfig setICEServers:@[server]];
Updated about a month ago
What's Next
Authentication |